I'm having trouble showing the errors returned from an API on my Sign up form when a user submits invalid data.
You can check out the error response in the console here: console ss
This is my approach in RegisterComponent.ts:
onSubmit() {
this.userService.register(this.registerForm.value).subscribe(response =>{
this.router.navigateByUrl('/shop');
}, error => {
console.log(error);
this.errorMessage = error.errors;
if(this.errorMessage) for(let err of this.errorMessage) console.log(err);
});
}
I also added this to the html:
<ul *ngIf="errorMessage">
<li *ngFor="let error of errorMessage">
{{error}}
</li>
</ul>
However, it doesn't seem to be working as expected. The errorMessage variable appears to be empty and I want it to show "An account already exists with this email". How can I correctly retrieve the error message?