簡體   English   中英

為什么像這樣在 subscribe/observable 上使用數據和錯誤現在在 Angular 中被棄用了?

[英]Why using the data and error on the subscribe/observable like this is now deprecated in angular?

為什么不推薦使用此代碼? 正確的形式如何?

 getPeopleFunction() {
this.peopleService.getPeopleService().subscribe(
  (data) => {
    console.log(data);
  },
  (error) => {
    console.log(error);
  }
);

}

您現在應該使用這種格式:

this.peopleService.getPeopleService().subscribe({
    next: (v) => console.log(v),
    error: (e) => console.error(e),
    complete: () => console.info('complete') 
})

https://rxjs.dev/deprecations/subscribe-arguments

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM