Answer the question
In order to leave comments, you need to log in
Why @ViewChildren does not see the second component and how to pass data async through Input?
In the parent component I have:
<app-filter *ngIf="interagencyFilters.doctypes | async as doctypes" [filter]="interagencyFilters.doctypes | async"></app-filter>
<app-filter *ngIf="interagencyFilters.status | async as status" [filter]="status"></app-filter>
<app-filter>
:@ViewChildren(FilterComponent) filtersList: QueryList<FilterComponent>;
ngAfterViewInit() {
console.log(this.filtersList.length);
}
console.log(this.filtersList.length);
gives me always the value 1. Even though there are two components on the page. app-filter [filter]="doctypes"></app-filter>
<app-filter [filter]="status"></app-filter>
ngOnInit() {
this.interagencyFilters.doctypes.subscribe((res) => (this.doctypes = res));
this.interagencyFilters.status.subscribe((res) => (this.status = res));
this.changeDetector.detectChanges();
}
Answer the question
In order to leave comments, you need to log in
> `console.log(this.filtersList.length);`
Need to use https://angular.io/api/core/QueryList#changes
this.filtersList.changes.subscribe((filters) => {
console.log(filters);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question