angular - How to call ViewChild in runtime? -
in angular2 , want find children components , declared in template in run time. how can it? example:
@component({ template: ` <cmp1 *ngif=expression></cmp1> <cmp2 *ngif=!expression></cmp2> ` }) export class component3{ findchild(){ // how find cmp2 } }
not sure mean "at runtime" how it's done:
@component({ template: ` <cmp1 #cmp *ngif=expression></cmp1> <cmp2 #cmp *ngif=!expression></cmp2> ` }) export class component3{ @viewchildren('cmp') cmp:querylist; findchild(){ return this.cmp.toarray()[0]; } }
component1
needs imported.
Comments
Post a Comment