我有 3 个要组合的事件,当其中一个事件被触发时,调用该服务。我用过combineLatest
,但只有当第一个事件被filterChanged
.
filterChanged
是一个本地事件,而其余的是来自子组件的事件。我该如何解决这个问题,以发出其中一个事件,甚至从页面初始化开始?
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);
}
谢谢