Seeking Guidance on Handling Deprecated 'Subscribe' in Angular

42 views Asked by At

Screenshot of htmlThis is my userUpdate() code Where i am facing subscribe getting deprecated. I am using PUT function and i will copy paste the code below.

`userUpdate() {
  if (this.userForm.valid) {
    console.log(this.userForm.value, 'updatedform');
    this.service.updateData(this.userForm.value,this.getparamId).subscribe((res) => {
        console.log(res, 'resupdated');
        this.successmessage = res.message;
        this.errormessage = null;
      },
      (error) => {
        console.error(error);
        if (error.error && error.error.message) {
          this.errormessage = error.error.message;
        } else {
          this.errormessage = 'An error occurred while updating data.';
        }
      }
    );
  } else {
    this.errormessage = 'All fields are required';
  }
}`

AND THIS IS MY HTML CODE

<div class="col-lg-4 mt-2" *ngIf="!getparamId">
  <!-- Use (click) instead of (onclick) -->
  <button class="btn btn-primary btn-sm" (click)="userSubmit()">Create</button>
</div>

<div class="col-lg-4 mt-2" *ngIf="getparamId">
  <!-- Use (click) instead of (onclick) -->
  <button class="btn btn-dark btn-sm" (click)="userUpdate()">Update</button>
</div>

(https://i.stack.imgur.com/c4izc.png)

(https://i.stack.imgur.com/SF1V8.png)

I tried so much to fix this issue but i couldnt, Whenever i click on the update button i am getting that error on console of the browser. PUT function is working properly but idk what is the problem. This project is basically a CRUD application. So do let me know if u need any more from my side. Thanks in advance!!!! :)

1

There are 1 answers

2
Matthieu Riegler On

You can use the method that accepts an object:

subscribe({
   next: () = {...}
   error: () = {...}
   complete: () = {...}
})`