Attempting to call a function from within a Promise.catch to handle for an error situation, but I'm not sure how to structure it to avoid getting an undefined reference
The goal is call an async login() function and if the password is invalid display a message to the user
// Log in user
login(email, password){
//send login request to firebase
this.af.auth.login(
{
email: email,
password: password
},
{
provider: AuthProviders.Password,
method: AuthMethods.Password,
}
).then(function(){
console.log('Success');
})
.catch(function(error){
this.showLoginErrorWindow(error);
);
}
// Display error message to user
// ** This function never gets called **
showLoginErrorWindow(message){
console.log('message: ' + message);
this.loginErrorMessage = 'Invalid email or password';
this.showLoginError = true; //Angular
}
Gives me the error:
TypeError: Cannot read property 'showLoginErrorWindow' of null