Notify component about error in service

It’s not much of news but Angular course is outdated and needs a refresh. However, I still find it useful but I need help with notifying component about error in service. In Angular 8 the pattern shown in the course, where you subscribe to both success and error, you can make component act based on error, was depreciated and now you only subscribe to success but not to error. Error gets handled in service object. Is there a new pattern that allows component to get notification about service error (and error object)?

I guess I had to ask the question to come up with answer, lol
Pre Angular 8 method call was: service.method().subscribe((result)=>{...}, (error)=>{...})
Angular 8 and higher: service.method().subscribe({next: (result)=>{..}, error: (error)=>{...}})
As simple as that, Art

1 Like

To build on this, if the user hovers over the deprecated subscribe signature, it will provide a link to the below page describing how it’s supposed to be used going forward.

ngOnInit(): void {
        next: (response) => {
          console.log("In subscribe response of GET...");
          this.posts = response as any[];
        error: (error) => {
          console.log("Error in GET...");
          alert("An unexpected error occurred in GET");
      complete: () => {
        console.log("Completed GET...");