当我打开缰绳时,上面写着:
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)
);
我不知道该用什么,怎么用……
谢谢!
我把我的Angular项目从TSLint迁移到ESLint,现在它不再显示警告了!
我遵循这些步骤。(在每个步骤结束时,我还建议提交更改)
Add eslint:
ng add @angular-eslint/schematics
Convert tslint to eslint:
ng g @angular-eslint/schematics:convert-tslint-to-eslint
Remove tslint and codelyzer: npm uninstall -S tslint codelyzer
If you like to auto fix many of the Lint issues
ng lint --fix (It will also list the not fixed issues)
In VSCode uninstall the TSLint plugin, install ESLint plugin and Reload the VSCode.
Make sure it updated the package and package-lock files. Also the node_modules in your project.
If you have the tsconfig.json files under sub directory - you need to add/update the projects-root-directory/.vscode/settings.json with the sub directory where the tsconfig files are!
{
"eslint.workingDirectories": [
"sub-directory-where-tsconfig-files-are"
]
}
VS Code官方页面的信息:从TSLint迁移到ESLint(谢谢你在评论中指出这一点!)
Angular从TSLint迁移到ESLint Reference
详见官方网站
https://rxjs.dev/deprecations/subscribe-arguments
注意下面第二个订阅代码中的{}大括号。
import { of } from 'rxjs';
// recommended
of([1,2,3]).subscribe((v) => console.info(v));
// also recommended
of([1,2,3]).subscribe({
next: (v) => console.log(v),
error: (e) => console.error(e),
complete: () => console.info('complete')
})
使用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: () => { }
}
);