From the course: Building Angular and ASP.NET Web API Apps

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Add data validation to a registered form

Add data validation to a registered form

From the course: Building Angular and ASP.NET Web API Apps

Add data validation to a registered form

- [Instructor] In this part, we're going to improve the errors in the signup page, and we are going to start from the component.ts file. In here, inside the class, just after the signupForm: form Group, I'm going to create a new property. Going to name it just errorMessage, and this is going to be of type either string or null. Default value is going to be just null. I'm going to use this one. Whenever I have an issue that is coming from the API side, I want to show a message on the screen. And then next, I'm going to create a helper method, which I'm going to use to check for specific errors in specific controllers. For that down here, just going to type, hasError. This will take two parameters. The first parameter is going to be the controlName, which is going to be, of course, of type string. And the second one is going to be the errorName, which is also going to be of type string. So, basically, we check, for example, for the email, if it has the error of the email format, this is…

Contents