【问题标题】:Using an Observable next - Typescript syntax使用 Observable next - Typescript 语法
【发布时间】:2023-04-07 19:16:02
【问题描述】:

如何调用 Observable next 回调?我没怎么用过打字稿,也不知道在哪里找语法。

观察者处理程序:

  editingBudgetDate: BudgetDate;
  editSubscriptionHandler = function(observer: Observer<BudgetDate>) {
    observer.next(this.editingBudgetDate);
    observer.complete;
  };

订阅 observable:

onBudgetDateEdit(): Observable<BudgetDate> {
    const update = new Observable(this.editSubscriptionHandler);
    return update;
}

广播新的订阅值(不知道如何)

editBudgetDate(budgetDate: BudgetDate) {
    this.editingBudgetDate = budgetDate;


    //this.editSubscriptionHandler; < -- next()  not sure how to do this
}

【问题讨论】:

    标签: typescript


    【解决方案1】:

    首先你可以创建 observable。

    updateSubject = new BehaviorSubject<any>('')
    public update = this.update.asObservable();
    

    之后,您可以将数据推送到

    this.updateSubject.next({send data});
    

    使用更新变量获取此数据

    update.subscribe(data => {})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 2023-02-11
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 2021-12-02
      相关资源
      最近更新 更多