Roshankumar Bisoi
Roshankumar Bisoi

Reputation: 31

Subscribe showing deprecated

this.userService.addUser(this.user).subscribe(
  (data)=>{
    //success
    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'],
    });
  }
);

I don't know what exactly is happening but subscribe showing deprecated, following is the message

(method) Observable<Object>.subscribe(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription (+2 overloads)
@deprecated — 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

'(next?: ((value: Object) => void) | null | undefined, error?: ((error: any) => void) | null | undefined, complete?: (() => void) | null | undefined): Subscription' is deprecated.ts(6385)
Observable.d.ts(55, 9): The declaration was marked as deprecated here.

By the way I am using Angular13

Upvotes: 2

Views: 7719

Answers (1)

Adithya Sreyaj
Adithya Sreyaj

Reputation: 1892

Just change it to:

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'],
    });
  }
});

Upvotes: 14

Related Questions