{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/4112","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/4112/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/4112/comments","events_url":"https://api.github.com/repos/angular/angular/issues/4112/events","html_url":"https://github.com/angular/angular/issues/4112","id":105758695,"number":4112,"title":"[router] CanActivate and DI","user":{"login":"cexbrayat","id":411874,"avatar_url":"https://avatars.githubusercontent.com/u/411874?v=3","gravatar_id":"","url":"https://api.github.com/users/cexbrayat","html_url":"https://github.com/cexbrayat","followers_url":"https://api.github.com/users/cexbrayat/followers","following_url":"https://api.github.com/users/cexbrayat/following{/other_user}","gists_url":"https://api.github.com/users/cexbrayat/gists{/gist_id}","starred_url":"https://api.github.com/users/cexbrayat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cexbrayat/subscriptions","organizations_url":"https://api.github.com/users/cexbrayat/orgs","repos_url":"https://api.github.com/users/cexbrayat/repos","events_url":"https://api.github.com/users/cexbrayat/events{/privacy}","received_events_url":"https://api.github.com/users/cexbrayat/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular/labels/comp:%20router-deprecated","name":"comp: router-deprecated","color":"c7def8"},{"url":"https://api.github.com/repos/angular/angular/labels/effort2:%20medium%20(day)","name":"effort2: medium (day)","color":"bfe5bf"},{"url":"https://api.github.com/repos/angular/angular/labels/P2:%20required","name":"P2: required","color":"fad8c7"},{"url":"https://api.github.com/repos/angular/angular/labels/type:%20feature","name":"type: feature","color":"EEEEEE"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":81,"created_at":"2015-09-10T08:29:58Z","updated_at":"2016-05-19T18:02:54Z","closed_at":null,"body":"The `CanActivate` hook is available as a decorator. \r\nThat's a bit surprising compared to all the other lifecycle hooks which are simple functions of the component. I understand the reason behind that (the hook is called before the component is instanciated), even if I think the API would be simpler if everything was a function...\r\n\r\nIf things stay like this, I have a question: will it be possible to use DI in the `CanActivate` hook?\r\n\r\nDo you plan to support something like : \r\n\r\n    @CanActivate((userService: UserService) => userService.isAdmin())\r\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/220404824","html_url":"https://github.com/angular/angular/issues/4112#issuecomment-220404824","issue_url":"https://api.github.com/repos/angular/angular/issues/4112","id":220404824,"user":{"login":"jkyoutsey","id":3846466,"avatar_url":"https://avatars.githubusercontent.com/u/3846466?v=3","gravatar_id":"","url":"https://api.github.com/users/jkyoutsey","html_url":"https://github.com/jkyoutsey","followers_url":"https://api.github.com/users/jkyoutsey/followers","following_url":"https://api.github.com/users/jkyoutsey/following{/other_user}","gists_url":"https://api.github.com/users/jkyoutsey/gists{/gist_id}","starred_url":"https://api.github.com/users/jkyoutsey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkyoutsey/subscriptions","organizations_url":"https://api.github.com/users/jkyoutsey/orgs","repos_url":"https://api.github.com/users/jkyoutsey/repos","events_url":"https://api.github.com/users/jkyoutsey/events{/privacy}","received_events_url":"https://api.github.com/users/jkyoutsey/received_events","type":"User","site_admin":false},"created_at":"2016-05-19T18:02:54Z","updated_at":"2016-05-19T18:02:54Z","body":"Does anyone have an example of how to unit test a class that depends on the app injector?  Since jasmine/karma abstracts the `bootstrap` process, how do I create/reference the injector in my unit test?\r\n\r\nIn main.ts\r\n```javascript\r\nbootstrap(AppComponent, [\r\n    ...\r\n]).then((appRef: ComponentRef<AppComponent>) => {\r\n        AppInjector.getInstance().setInjector(appRef.injector);\r\n    },\r\n    error => console.log(error)\r\n    );\r\n```\r\nIn class constructor:\r\n```javascript\r\n        let injector: AppInjector = AppInjector.getInstance();\r\n        this.uiStateService = injector.getInjector().get(UiStateService);\r\n```\r\n\r\nAll works.  But unit tests can't find the injector."}}