Answer the question
In order to leave comments, you need to log in
@ViewChild throws undefined due to ngIf, how to solve the problem?
I have a parent component and it looks like this.
export class ParentComponent {
@ViewChild(ChildComponent) childComponent: ChildComponent;
public showChild: boolean = false;
clickHandler() {
this.showChild = true;
this.childComponent.setSomething()
}
}
<child *ngIf="showChild "></child >
ERROR TypeError: Cannot read property 'setSomething' of undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question