When i enter this code .subscribe gets lined on it and due to this my data is not saved

Viewed 22
 .subscribe(() => {
  console.log('Data Added Sucessfully!')
  this.ngZone.run(() => this.router.navigateByUrl('/books-list'))
  }, (err) => {
    console.log(err);
});

In the first line .subscribe work marked as lined on it (strikethrough) and due to this data cannot be saved

1 Answers

Striked is because subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription method is depreciated. https://rxjs.dev/api/index/class/Observable#subscribe

Use Observer object if you need to perform actions on error or completion too:

.subscribe({
  next: (value: T) => void
  error: (err: any) => void
  complete: () => void
})

Anyway, your code should work despite it's depreciated. Had you provided more details about observable, we would have been able to provide solution.

Related