typescript 从订阅触发错误或完成

uinbv5nw  于 2022-12-05  发布在  TypeScript
关注(0)|答案(1)|浏览(134)

我是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(); 
  }
}

相关问题