{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/8277","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/8277/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/8277/comments","events_url":"https://api.github.com/repos/angular/angular/issues/8277/events","html_url":"https://github.com/angular/angular/issues/8277","id":151363766,"number":8277,"title":"How to access the host component from a directive ?","user":{"login":"frankpepermans","id":3460003,"avatar_url":"https://avatars2.githubusercontent.com/u/3460003?v=4","gravatar_id":"","url":"https://api.github.com/users/frankpepermans","html_url":"https://github.com/frankpepermans","followers_url":"https://api.github.com/users/frankpepermans/followers","following_url":"https://api.github.com/users/frankpepermans/following{/other_user}","gists_url":"https://api.github.com/users/frankpepermans/gists{/gist_id}","starred_url":"https://api.github.com/users/frankpepermans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frankpepermans/subscriptions","organizations_url":"https://api.github.com/users/frankpepermans/orgs","repos_url":"https://api.github.com/users/frankpepermans/repos","events_url":"https://api.github.com/users/frankpepermans/events{/privacy}","received_events_url":"https://api.github.com/users/frankpepermans/received_events","type":"User","site_admin":false},"labels":[{"id":375501288,"url":"https://api.github.com/repos/angular/angular/labels/comp:%20core%20&%20compiler","name":"comp: core & compiler","color":"c7def8","default":false},{"id":130606845,"url":"https://api.github.com/repos/angular/angular/labels/type:%20feature","name":"type: feature","color":"EEEEEE","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/angular/angular/milestones/82","html_url":"https://github.com/angular/angular/milestone/82","labels_url":"https://api.github.com/repos/angular/angular/milestones/82/labels","id":3045967,"number":82,"title":"Backlog","description":"Milestone for triaged issues that have not yet been scheduled for resolution.","creator":{"login":"IgorMinar","id":216296,"avatar_url":"https://avatars3.githubusercontent.com/u/216296?v=4","gravatar_id":"","url":"https://api.github.com/users/IgorMinar","html_url":"https://github.com/IgorMinar","followers_url":"https://api.github.com/users/IgorMinar/followers","following_url":"https://api.github.com/users/IgorMinar/following{/other_user}","gists_url":"https://api.github.com/users/IgorMinar/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorMinar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorMinar/subscriptions","organizations_url":"https://api.github.com/users/IgorMinar/orgs","repos_url":"https://api.github.com/users/IgorMinar/repos","events_url":"https://api.github.com/users/IgorMinar/events{/privacy}","received_events_url":"https://api.github.com/users/IgorMinar/received_events","type":"User","site_admin":false},"open_issues":1713,"closed_issues":118,"state":"open","created_at":"2018-01-18T16:52:20Z","updated_at":"2018-05-09T21:00:30Z","due_on":null,"closed_at":null},"comments":59,"created_at":"2016-04-27T11:34:42Z","updated_at":"2018-05-10T11:51:25Z","closed_at":null,"author_association":"NONE","body":"According to the change log (https://github.com/angular/angular/blob/master/CHANGELOG.md),\nAppViewManager is renamed into ViewUtils and is a mere private utility service.\n\nHowever, I was using `AppViewManager.getComponent` to obtain a Component reference from an ElementRef before, how would I do this now?\n\nWhat I need to achieve is the following:\n- I have a Component with a selector (say: selector my-component)\n- A directive that can be placed upon Components (my-directive)\n\nIn HTML, it looks as following\n`<my-component my-directive></my-component>`\n\nFrom my-directive, I need to have a reference to the my-component Component instance.\n\nIf there is another (better) way of doing this, I'm happy to adapt my code\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/388031831","html_url":"https://github.com/angular/angular/issues/8277#issuecomment-388031831","issue_url":"https://api.github.com/repos/angular/angular/issues/8277","id":388031831,"user":{"login":"rbrzoska","id":9517020,"avatar_url":"https://avatars3.githubusercontent.com/u/9517020?v=4","gravatar_id":"","url":"https://api.github.com/users/rbrzoska","html_url":"https://github.com/rbrzoska","followers_url":"https://api.github.com/users/rbrzoska/followers","following_url":"https://api.github.com/users/rbrzoska/following{/other_user}","gists_url":"https://api.github.com/users/rbrzoska/gists{/gist_id}","starred_url":"https://api.github.com/users/rbrzoska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbrzoska/subscriptions","organizations_url":"https://api.github.com/users/rbrzoska/orgs","repos_url":"https://api.github.com/users/rbrzoska/repos","events_url":"https://api.github.com/users/rbrzoska/events{/privacy}","received_events_url":"https://api.github.com/users/rbrzoska/received_events","type":"User","site_admin":false},"created_at":"2018-05-10T11:51:25Z","updated_at":"2018-05-10T11:51:25Z","author_association":"NONE","body":"There is a solution for that:\r\n\r\nyou need to define some abstract class or a token\r\n`export abstract class MyAbstractComponent {\r\n// some public methods that should be available in directive\r\n}\r\n`\r\nthen in component you should extend abstract class and provide it \r\n\r\n@Component({\r\n...\r\nproviders:[{provide: MyAbstractComponent, useExisting:  forwardRef(() => MyComponent ) ]\r\n})\r\nexport class MyComponent extends MyAbstractComponent {\r\n... implement  abstract class\r\n}\r\n`\r\nand finally in directive just inject component instance as abstract class\r\n\r\n`@Directive({\r\n})\r\nexport class MyDirective implements OnInit {\r\n\r\n  constructor(private component: MyAbstractComponent ) {}\r\n\r\n  ngOnInit() {\r\n    this.component.....\r\n  }\r\n}`"}}
{"actor":{"display_login":"rbrzoska"}}