I'm new to angular. I was trying something and got stuck. In my form, I want to show server validation response as error coming from a laravel rest api. But don't know how to store and show it in the template. I am able to log it to the console but not able to move further with the error message.
The response is somewhat like this-
{
"message": {
"firstname":["The firstname field is required."],
"lastname":["The lastname field is required."],
"email":["The email field is required."],
"password":["The password field is required."]
}
}
The Service code:
registerUser(user): Observable<any> {
return this.http
.post<any>(`${this.url}/register`, user)
.pipe(map(res => res.message));
}
The register user method in component class:
registerUser() {
console.log(this.registrationForm.value);
this.authService.registerUser(this.registrationForm.value).subscribe(
res => console.log(res),
err => console.log(err)
);
}
Also, correct me if I'm going wrong anywhere and how should I correct it