I'm trying the get an ElementRef for a child component from its parent component.
@Component({
moduleId: module.id,
selector: 'parent',
templateUrl: 'parent.component.html',
directives: [
Child1Component,
Child2Component
]
})
In the html for Child1Component I have
<button class="btn btn-primary" #myRef>Select File</button>
In the class for the parent:
export class ParentComponent implements OnInit {
@ViewChild('myRef') myRef: ElementRef;
// ...
But of course when I try to access the child ElementRef in the parent class...
ngAfterViewInit() {
console.log(this.myRef.nativeElement);
...I get undefined. How should I get the ElementRef? Thanks!