angular - Return values from components in ngFor loop -
i have following html in main component:
<app-loc-list-item *ngfor="let loc of locs; let = index" [loc]="loc" [i]="i"></app-loc-list-item>
the loclistitemcomponent
looks this:
import { component, oninit, input } '@angular/core'; .... export class loclistitemcomponent implements oninit { @input() loc: location; @input('i') index: number; selected: boolean = false; onlocationselect() { this.selected = !this.selected; } }
now, there can number of little components , between 0
, n
can have value selected = true
. want receive index
values each of components have selected = true
.
how can access index values?
if want query 'app-loc-list-item' children parent component include line of code in parent
@viewchildren(loclistitem) listitems: querylist<loclistitem>
so can iterate on listitems property in parent , see ones have been selected
Comments
Post a Comment