简体   繁体   English

为什么像这样在 subscribe/observable 上使用数据和错误现在在 Angular 中被弃用了?

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

Why is this code deprecated?为什么不推荐使用此代码? and how is the correct form?正确的形式如何?

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

} }

You should use this format now:您现在应该使用这种格式:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM