Take a look at this sample class:
class LoginController{
constructor(authService,$timeout,$state){
let vm = this;
this.loading = false;
this._authService = authService;
this._$timeout = $timeout;
this._$state = $state;
this.loading = false;
this.statusMessage = null;
}
login(){
this.loading = true;
this.statusMessage = null;
let loginModel = {
UserName : this.username,
Password : this.password,
RememberMe : this.rememberMe
};
//Login User
this._authService.login(loginModel).then(function(user){
//Set User Login & send to Dashboard
this._authService.setUser(user);
this._$state.go("dashboard");
}, function(error){
const errorMessage = error ? error.Message : "Undefined Login Issue occurred !";
this.loading = false;
});
}
}
All is functioning as expected, except for when the error callback function triggers and reaches this.loading = false;
resulting in an "undefined" error.
Is there a way to maintain a reference to the Class "this" within the error callback?