I have input box inside two divs that render conditionally.
html
<div ngIf="show==true">
<input #ref />
</div>
<div ngIf="show==true">
<input #ref />
</div>
.ts
@ViewChild('ref ') ref : ElementRef;
ngOnInit(){
if(someCondition){
show = true;
}
Observable.fromEvent(this.ref .nativeElement, 'keyup');
}
It shows the undefind ref as ref variable declared before ngOnInit
I believe we cannot initialize viewchild later,
What could be alternate solution.
Thanks