rxjs subcribe已弃用
我在subcribe方法方面遇到了麻烦。在VSCODE中,它说sudcribe被弃用了,但我不知道如何正确更改它。
public getAccount(): void{
this.accountService.getAccounts().subscribe(
(response: Account[]) => {
this.accounts = response;
},
(error: HttpErrorResponse) => {
alert(error.message);
}
)
}
I have trouble with subcribe method. In vscode it says that subcribe is deprecated but I have no clue how to change it properly.
public getAccount(): void{
this.accountService.getAccounts().subscribe(
(response: Account[]) => {
this.accounts = response;
},
(error: HttpErrorResponse) => {
alert(error.message);
}
)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该通过观察者对象而不是多个回调对象。所有使用多个参数的签名均已弃用。
如果您不需要错误并完成回调,则仍然可以这样使用:
.subscribe((value)=> console.log(value))
。您可以阅读有关您使用的签名为何被弃用。
You should pass an observer object instead of multiple callbacks. All signatures that used multiple arguments were deprecated.
If you don't need an error and complete callbacks, you can still use it like this:
.subscribe((value) => console.log(value))
.You can read about why the signature you're using was deprecated here.