1

I'm trying to set the this.signinError within the catch block. however when the console.log(this.signinError); is called it keep returning undefined. When I do it before the function call, it returns an empty string as defined in the beginning of the class. What am I doing wrong here?

@inject(UserService)
export class LoginComponent {

  email = '';
  password = '';

  signinError = '';

  constructor(userService) {
    this.userService = userService
  }

  login() {
    console.log(this.signinError);
    this.userService.login(this.email, this.password).catch(function(error) {
      console.log(this.signinError);
      this.signinError = error.message;
    });
  }
}
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Peter Pik
  • 11,023
  • 19
  • 84
  • 142

0 Answers0