订阅显示已弃用

Ros*_*soi 2 rxjs7

this.userService.addUser(this.user).subscribe(\n  (data)=>{\n    //success\n    console.log(data);\n    this._snack.open('Registered Successfully', 'OK', {\n      duration: 2000,\n      verticalPosition: 'top',\n      horizontalPosition: 'center',\n      panelClass: ['green-snackbar', 'login-snackbar'],\n    });\n  },\n  (error)=>{\n    //error\n    console.log(error);\n    this._snack.open('Something went Wrong', 'OK', {\n      duration: 2000,\n      verticalPosition: 'top',\n      horizontalPosition: 'center',\n      panelClass: ['red-snackbar','login-snackbar'],\n    });\n  }\n);\n
Run Code Online (Sandbox Code Playgroud)\n

我不知道到底发生了什么,但订阅显示已弃用,以下是消息

\n
(method) Observable<Object>.subscribe(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription (+2 overloads)\n@deprecated \xe2\x80\x94 Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments\n\n'(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription' is deprecated.ts(6385)\nObservable.d.ts(55, 9): The declaration was marked as deprecated here.\n
Run Code Online (Sandbox Code Playgroud)\n

顺便说一句,我正在使用 Angular13

\n

Adi*_*yaj 14

只需将其更改为:

this.userService.addUser(this.user).subscribe({
  next: (data) => {
    console.log(data);
    this._snack.open('Registered Successfully', 'OK', {
      duration: 2000,
      verticalPosition: 'top',
      horizontalPosition: 'center',
      panelClass: ['green-snackbar', 'login-snackbar'],
    });
  },
  error: (error) => {
    console.log(error);
    this._snack.open('Something went Wrong', 'OK', {
      duration: 2000,
      verticalPosition: 'top',
      horizontalPosition: 'center',
      panelClass: ['red-snackbar','login-snackbar'],
    });
  }
});
Run Code Online (Sandbox Code Playgroud)