{"action":"created","issue":{"url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/22","labels_url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/22/comments","events_url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/22/events","html_url":"https://github.com/hannahhoward/a1atscript/issues/22","id":94201987,"number":22,"title":"Add some way to mimick the various dependency injections in ng2 (@Parent, @Query, etc)","user":{"login":"timkindberg","id":168046,"avatar_url":"https://avatars.githubusercontent.com/u/168046?v=3","gravatar_id":"","url":"https://api.github.com/users/timkindberg","html_url":"https://github.com/timkindberg","followers_url":"https://api.github.com/users/timkindberg/followers","following_url":"https://api.github.com/users/timkindberg/following{/other_user}","gists_url":"https://api.github.com/users/timkindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/timkindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timkindberg/subscriptions","organizations_url":"https://api.github.com/users/timkindberg/orgs","repos_url":"https://api.github.com/users/timkindberg/repos","events_url":"https://api.github.com/users/timkindberg/events{/privacy}","received_events_url":"https://api.github.com/users/timkindberg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-10T03:05:49Z","updated_at":"2015-08-31T13:12:58Z","closed_at":null,"body":"See: https://angular.io/docs/js/latest/api/annotations/DirectiveAnnotation-class.html. There are various dependencies you can inject into the controller class constructor.\r\n\r\n1. `directive:DirectiveType`: a directive on the current element only\r\n2. `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current element and the Shadow DOM root. Current element is not included in the resolution, therefore even if it could resolve it, it will be ignored.\r\n3. `@Parent() directive:DirectiveType`: any directive that matches the type on a direct parent element only.\r\n4. `@Query(DirectiveType) query:QueryList<DirectiveType>`: A live collection of direct child directives.\r\n5. `@QueryDescendants(DirectiveType) query:QueryList<DirectiveType>`: A live collection of any child directives.\r\n\r\nIn angular 1:\r\n* 1 is similar to using a `require: 'dependency'`. So no implementation needed.\r\n* 2 & 3 are similar to `require: '^depencency'. So no implementation needed.\r\n* 4 & 5 don't have a direct correlation in ng1. We'd have to write a custom method that queried child directives and watched for changes so it was live. Also the found children would have to properly reference each child's controller class instance.\r\n\r\nThoughts on 4 & 5: Perhaps an api like this would be possible, where we auto-generate a $Query method on every component class that would help with this:\r\n```js\r\n@Component({ selector: 'child-a' })\r\nclass ChildA {\r\n  foo() { console.log('foo') }\r\n}\r\n\r\n@Component()\r\n@View({\r\n  inline: `\r\n    <child-a/>\r\n    <child-a/>\r\n  `\r\n})\r\nclass MyComponent {\r\n  constructor() {\r\n    let childrenA = this.$Query(ChildA);\r\n    console.log(childrenA.length); // outputs 2\r\n    console.log(childrenA[0].foo()); // outputs 'foo'\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/comments/136367108","html_url":"https://github.com/hannahhoward/a1atscript/issues/22#issuecomment-136367108","issue_url":"https://api.github.com/repos/hannahhoward/a1atscript/issues/22","id":136367108,"user":{"login":"timkindberg","id":168046,"avatar_url":"https://avatars.githubusercontent.com/u/168046?v=3","gravatar_id":"","url":"https://api.github.com/users/timkindberg","html_url":"https://github.com/timkindberg","followers_url":"https://api.github.com/users/timkindberg/followers","following_url":"https://api.github.com/users/timkindberg/following{/other_user}","gists_url":"https://api.github.com/users/timkindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/timkindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timkindberg/subscriptions","organizations_url":"https://api.github.com/users/timkindberg/orgs","repos_url":"https://api.github.com/users/timkindberg/repos","events_url":"https://api.github.com/users/timkindberg/events{/privacy}","received_events_url":"https://api.github.com/users/timkindberg/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T13:12:58Z","updated_at":"2015-08-31T13:12:58Z","body":"@PascalPrecht we are looking into some of these other things over at the new ng-forward project. https://github.com/ngUpgraders/ng-forward"}}