I am currently watchin a tutorial, and I'm really keeping an eye on what's going on. However, I am constantly getting this error:
ERROR TypeError: Cannot read property 'forEach' of undefined
This is my part of code where I get that:
onSubmit(){
this.service.register().subscribe(
(res: any) => {
if (res.succeeded){
this.service.formModel.reset();
this.toastr.success('Korisnik kreiran!', 'Registracija uspješna!');
} else {
res.errors.forEach((element:any)=>{
switch (element.code){
case 'DuplicateUserName':
this.toastr.error('Korisničko ime se već koristi.', 'Neuspjela registracija.');
break;
//Registration failed
default:
this.toastr.error(element.description, 'Neuspjela registracija.');
break;
}
});
}
},
err=>{
console.log(err);
}
);
}
Does anybody has idea what's going on? Thanks.