{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/4015","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/4015/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/4015/comments","events_url":"https://api.github.com/repos/angular/angular/issues/4015/events","html_url":"https://github.com/angular/angular/issues/4015","id":105047956,"number":4015,"title":"Equivalent to resolve in Component Router?","user":{"login":"robwormald","id":534930,"avatar_url":"https://avatars.githubusercontent.com/u/534930?v=3","gravatar_id":"","url":"https://api.github.com/users/robwormald","html_url":"https://github.com/robwormald","followers_url":"https://api.github.com/users/robwormald/followers","following_url":"https://api.github.com/users/robwormald/following{/other_user}","gists_url":"https://api.github.com/users/robwormald/gists{/gist_id}","starred_url":"https://api.github.com/users/robwormald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robwormald/subscriptions","organizations_url":"https://api.github.com/users/robwormald/orgs","repos_url":"https://api.github.com/users/robwormald/repos","events_url":"https://api.github.com/users/robwormald/events{/privacy}","received_events_url":"https://api.github.com/users/robwormald/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular/labels/comp:%20router","name":"comp: router","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/hotlist:%20A2%20Blocking","name":"hotlist: A2 Blocking","color":"d4c5f9"},{"url":"https://api.github.com/repos/angular/angular/labels/hotlist:%20angular-core-team","name":"hotlist: angular-core-team","color":"d4c5f9"},{"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":{"url":"https://api.github.com/repos/angular/angular/milestones/54","html_url":"https://github.com/angular/angular/milestones/Angular%202%20Release%20Candidate","labels_url":"https://api.github.com/repos/angular/angular/milestones/54/labels","id":1627788,"number":54,"title":"Angular 2 Release Candidate","description":"Issues that are slated for Angular 2 RC","creator":{"login":"naomiblack","id":2286589,"avatar_url":"https://avatars.githubusercontent.com/u/2286589?v=3","gravatar_id":"","url":"https://api.github.com/users/naomiblack","html_url":"https://github.com/naomiblack","followers_url":"https://api.github.com/users/naomiblack/followers","following_url":"https://api.github.com/users/naomiblack/following{/other_user}","gists_url":"https://api.github.com/users/naomiblack/gists{/gist_id}","starred_url":"https://api.github.com/users/naomiblack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/naomiblack/subscriptions","organizations_url":"https://api.github.com/users/naomiblack/orgs","repos_url":"https://api.github.com/users/naomiblack/repos","events_url":"https://api.github.com/users/naomiblack/events{/privacy}","received_events_url":"https://api.github.com/users/naomiblack/received_events","type":"User","site_admin":false},"open_issues":45,"closed_issues":66,"state":"open","created_at":"2016-03-08T00:52:34Z","updated_at":"2016-04-28T23:41:16Z","due_on":null,"closed_at":null},"comments":16,"created_at":"2015-09-05T20:43:28Z","updated_at":"2016-05-02T16:54:17Z","closed_at":null,"body":"With the removal of the @InjectPromise and @InjectLazy decorators, is there an equivalent functionality to resolve in ngRoute/uiRouter? \r\n\r\nThe angular1 version would look something like:\r\n```js\r\n//controller\r\nfunction MyController(foo){}\r\n\r\n//route config\r\n{\r\n  controller: 'MyController',\r\n  url: 'foos/:fooId',\r\n  resolve: {  \r\n    foo: function($routeParams,FooService){ return FooService.getFooById($routeParams.fooId); }\r\n  }\r\n}\r\n```\r\nThis is IMO, one of the killer features of the current router and UI-router, as it remove async entirely from the controller and makes it super easy to test. The canActivate etc hooks cover one of the use cases for resolve (preventing access to routes/state), but I can't see a replacement for the above case. Perhaps I'm missing something?\r\n\r\nI've been tinkering with an idea like this for NG2, implementing resolve as a decorator:\r\n```js\r\n@Component({ selector: 'foo-detail' })\r\n@View({ template: '<div>{{foo.name}}</div>'})\r\n//token : resolver : injectables\r\n@Resolve(Foo, (params, fooService) => fooService.getFooById(params.fooId), [RouteParams, FooService])\r\nclass FooDetailComponent {\r\n  constructor(public foo: Foo){}\r\n}\r\n```\r\nAn alternative syntax might look like:\r\n```js\r\n@Resolve({\r\n  foo(params:RouteParams, fooService:FooService){ return fooService.getFooById(params.fooId) }\r\n})\r\n```\r\nThough that limits you to string keys and I can't figure a way to pass bindings, and I'm not sure reflect will allow us to grab the metadata annotations this way.\r\n\r\nUnder the hood, it keeps async out of the injector, as its \"simply\" a matter of executing the resolver fn before passing them to the component's overridden bindings. Thoughts?\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/216291131","html_url":"https://github.com/angular/angular/issues/4015#issuecomment-216291131","issue_url":"https://api.github.com/repos/angular/angular/issues/4015","id":216291131,"user":{"login":"syndicatedshannon","id":905156,"avatar_url":"https://avatars.githubusercontent.com/u/905156?v=3","gravatar_id":"","url":"https://api.github.com/users/syndicatedshannon","html_url":"https://github.com/syndicatedshannon","followers_url":"https://api.github.com/users/syndicatedshannon/followers","following_url":"https://api.github.com/users/syndicatedshannon/following{/other_user}","gists_url":"https://api.github.com/users/syndicatedshannon/gists{/gist_id}","starred_url":"https://api.github.com/users/syndicatedshannon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syndicatedshannon/subscriptions","organizations_url":"https://api.github.com/users/syndicatedshannon/orgs","repos_url":"https://api.github.com/users/syndicatedshannon/repos","events_url":"https://api.github.com/users/syndicatedshannon/events{/privacy}","received_events_url":"https://api.github.com/users/syndicatedshannon/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T16:54:17Z","updated_at":"2016-05-02T16:54:17Z","body":"I'm glad this is on the hotlist.\r\n\r\nCan someone please comment on the intention (or lack of intention) to support this on AuxRoute as well?\r\n\r\nWe're in a bind where, since AuxRoute does not process the CanActivate hook, the workaround is not working; and we cannot build aux components that are responsible for their own data, or move/reuse components between Aux and Primary routes.\r\n\r\nAlso, does anyone listening have a suggestion on a similar workaround for AuxRoutes?"}}