我是Angular的新手,我正在尝试触发订阅中的错误回调。我正在操作一个表对象,并希望在触发器变为true
时抛出吐司。通过错误或完成。
// editCollection.component.ts
handleMoveRowsDown() {
this.collectionsStore.moveRowsDown(this.selectedRows).subscribe(
(collection) => {
this.table.sorts = [];
this.rowsSorted = true;
this.collection = collection;
this.table.rows = this.collection.rows;
},
(error) => {
console.error(error);
this.toastr.error("You've hit bottom!"); // throw toast if "trigger" is true
this.selectedRows = [];
}
);
}
// collections.store.ts
moveRowsDown(selectedRows: DtRow[]): Observable<DtCollection> {
let trigger = false;
// manipulate table...
if (trigger) {
throw new Error(); // this does not work
} else {
this.setCurrentCollection(tempCollection as DtCollection);
// how do I return trigger along with the asObservable?
return this._currentCollection.asObservable();
}
}
1条答案
按热度按时间kyvafyod1#
通过
throwError()
返回带有错误示例的可观察结果。第一个
Dummy Demo @ StackBlitz