Answer the question
In order to leave comments, you need to log in
How to get variable value from QueryList?
I use the following construct to access child components:
@ViewChildren(FilterComponent) filtersList: QueryList;
Inside template I have:
<button [disabled]="!filterHasChanges()">
And handler:
public filterHasChanges(): boolean {
return this.filtersList.reduce((acc: boolean, b) => acc || b.filter.selected.length > 0, false);
}
b.filter.selected.length > 0
filterHasChanges()
works faster than the children build, I get an error:TypeError: Cannot read property 'reduce' of undefined
at OrdersExecutionSidebarComponent.filterHasChanges
Remember -
The QueryList is initialized only before the ngAfterViewInit lifecycle hook, therefore, is available only from this point.
Answer the question
In order to leave comments, you need to log in
buttonDisabled = this.filtersList.changes.pipe(
map(list => list.reduce((acc: boolean, b) => acc || b.filter.selected.length > 0, false),
)
<button [disabled]="!(buttonDisabled | async)">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question