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.

see angular 2 / typescript : hold of element in template


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -