当我打开缰绳时,上面写着:
subscribe is deprecated: Use an observer instead of an error callback
angular应用的代码:
this.userService.updateUser(data).pipe(
tap(() => {bla bla bla})
).subscribe(
this.handleUpdateResponse.bind(this),
this.handleError.bind(this)
);
我不知道该用什么,怎么用……
谢谢!
也许有趣的是,观察者对象也可以(仍然)包含complete()方法和其他附加属性。例子:
.subscribe({
complete: () => { ... }, // completeHandler
error: () => { ... }, // errorHandler
next: () => { ... }, // nextHandler
someOtherProperty: 42
});
这样可以更容易地省略某些方法。对于旧的签名,必须提供未定义的并坚持参数的顺序。现在,只提供下一个完整的处理程序就清楚多了。
使用RxJS的新方法非常简单:
以前的版本:
this.activatedRoute.queryParams.subscribe(queryParams => {
console.log("queryParams, queryParams)
}, error => {
})
新版本:
this.activatedRoute.queryParams.subscribe(
{
next: (queryParams) => {
console.log('queryParams', queryParams);
},
error: (err: any) => { },
complete: () => { }
}
);