Interview Questions

1. What is the best way to perform Error handling in Angular?

Error is when the request fails on the server or fails to reach the server due to network issues. In this condition, HttpClient returns an error object instead of a successful response. To resolve this issue, we must handle the component by passing the error object as a second callback to the subscribe() method.

See the following example to understand how we handle the component:

fetchUser() {  

  this.userService.getProfile()  

    .subscribe(  

      (data: User) => this.userProfile = { ...data }, // success path  

      error => this.error = error // error path  

    );  

}  

You can write an error message to give the user some meaningful feedback instead of displaying the raw error object returned from HttpClient.


By Md Riyazuddin 2 0
Is this helpful? Yes No

Submit an interview question

Submitted questions and answers are subject to review and editing, and may or may not be selected for posting, at the sole discretion of w3Sniff.

Get Started

Comments

Leave a Comment


Check out more interview questions

Based on your skills

MS SQL Server

89933 1720 3 860

Angular

2419 92 0 46

Wordpress

1872 72 0 36
AD Ad-Free