Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

viewchild for ngfor

<div *ngFor="let v of views">
    <customcomponent #cmp></customcomponent>
</div>

-------------------------

import { ViewChildren, QueryList } from '@angular/core';

/** Get handle on cmp tags in the template */
@ViewChildren('cmp') components:QueryList<CustomComponent>; // or ElementRef if only need to grab element

ngAfterViewInit(){
    // print array of CustomComponent objects
    console.log(this.components.toArray());
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #viewchild #ngfor
ADD COMMENT
Topic
Name
9+9 =