For example we have a component: <Card ></Card> And a driective: <Card highlighted></Card> We want to get the driective instant inside the component code, we can use @ViewChild: @ViewChild(CardComponennt, {read: HighlightedDirectiv…
It is not clear in the Docs about {read: xx} option for @ViewChild. Based on the Source code, @ViewChild as view as Component, ElementRef, TemplateRef. For example, we have: <one></one> @ViewChild(OneComponent) one: OneComponent; ngAfterViewIn…
We can use @ViewChild with component: @ViewChild(AuthMessageComponent) message: AuthMessageComponent; //.... ngAfterContentInit() { if (this.message) { ; } } By doing this, we actually can access component's prop and events. If we want to get compone…
ElementRef: In Angular2 Doc, it suggest to "avoid" using ElementRef. It access DOM directly, can easily be attacked. import {Component, OnInit, ViewChild, Renderer, ElementRef} from '@angular/core'; @Component({ moduleId: module.id, selector: 'w…