订阅已弃用:使用观察者而不是错误回调 [英] Subscribe is deprecated: Use an observer instead of an error callback

查看:33
本文介绍了订阅已弃用:使用观察者而不是错误回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 linter 时,它说:

When I run the linter it says:

subscribe is deprecated: Use an observer instead of an error callback

代码(来自带有 angular-cli 的 angular 7 应用程序):

Code (from an angular 7 app with angular-cli):

    this.userService.updateUser(data).pipe(
       tap(() => {bla bla bla})
    ).subscribe(
       this.handleUpdateResponse.bind(this),
       this.handleError.bind(this)
    );

不知道我应该使用什么以及如何使用...

Don't know exactly what should I use and how...

谢谢!

推荐答案

subscribe 未弃用,仅弃用了您使用的变体.将来,subscribe 将只接受一个参数:next 处理程序(一个函数)或一个观察者对象.

subscribe isn't deprecated, only the variant you're using is deprecated. In the future, subscribe will only take one argument: either the next handler (a function) or an observer object.

所以在你的情况下你应该使用:

So in your case you should use:

.subscribe({
   next: this.handleUpdateResponse.bind(this),
   error: this.handleError.bind(this)
});

查看这些 GitHub 问题:

See these GitHub issues:

https://github.com/ReactiveX/rxjs/issues/4159

这篇关于订阅已弃用:使用观察者而不是错误回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆