When I attempt to set a property 'error' that is undefined, I receive a TypeError. The problematic line of code looks like this: this.error = error.code;
This issue arises in an Angular Reactive Form while making a call to a web service. Below is the relevant snippet:
@Component({
// ...
})
export class SignUpComponent implements OnInit {
// More declarations...
error: string | null; // I also tried error = '' and error = null
// Constructor, etc.
public submit() {
this.error = null;
if (this.signUpForm.valid) {
// Create an Auth0 user
this.authService.signUp(this.signUp.value.email, this.signUp.value.password, this.authServiceCallback);
}
}
public authServiceCallback(error) {
if (error) {
// This will cause an error child component to appear
this.error = error.code;
} else {
// Do something else
}
}
}
I'm puzzled by what mistake I might be making. Any insights?