Answer the question
In order to leave comments, you need to log in
How to get child elements created by ngFor?
<select [(ngModel)]="selectedId" appSelect>
<option #option *ngFor="let item of Items" [ngValue]="item.id ">{{item.name}}</option>
</select>
@ContentChildren('option') options: QueryList<ElementRef>;
...
ngContentViewInit() {
this.options.changes.subscribe(...);
}
Answer the question
In order to leave comments, you need to log in
Artem , there is another option. It is similar, but it can be found in various creators of a bunch of all sorts of components for angular.
<div class="table-body">
<ul class="table-list"
directiveList>
<li *ngFor="let item of items; let i = index; trackBy: trackByFn"
class="table-item" directiveItem>
{{item}}
</li>
</ul>
</div>
@Directive({
selector: '[directiveList]',
exportAs: 'directiveList'
})
export class DirectiveList {
/**
* Children directives which placed on items
*/
@ContentChildren(DirectiveItem, {read: ElementRef}) // получаем сразу как список ссылок на компоненты класса
private _items: QueryList<DirectiveItem>;
}
ngAfterContentInit() {
this._items.changes.subscribe(() => {
this.coolFunc();
});
}
@Directive({
selector: '[directiveItem]'
})
export class ClassNewInViewItemDirective {
constructor() { }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question