I have 3 events which I want to combine, and when one of them is fired, to call the service. I used combineLatest
, but it works only if the first event is fired by the filterChanged
.
filterChanged
is an local event, while the rest are events comed from the child component. How can I fix this, to emit one of the events, even from the page initialization?
filterChanged = new EventEmitter<boolean>();
paginatorChanged = new EventEmitter<MatPaginator>();
sortChanged = new EventEmitter<{}>();
ngAfterViewInit(): void {
combineLatest(
this.paginatorChanged,
this.sortChanged,
this.filterChanged
).pipe(
startWith([null, null, null]),
switchMap(value => {
const paginator = value[0];
const sort = value[1];
const filters = value[2];
return this.service.getFiltered(paginator, sort, filters);
})).subscribe(data => this.data = data);
}
applyFilter(): void {
this.filterChanged.emit(true);
}
onPaginatorChanged(paginator): void {
this.paginatorChanged.emit(paginator);
}
onSortChanged(sort): void {
this.sortChanged.emit(sort);
}
thanks