Aurelia 如何从login.ts到login.html获取登录错误的结果

Aurelia 如何从login.ts到login.html获取登录错误的结果,aurelia,Aurelia,我是奥雷利亚的新手,有一些Javascript方面的背景。特别是,我从中汲取灵感,并将两者结合起来 我能够成功地调用AWS Cognito并获得不同的验证结果。我知道,通过在firefox中打开开发者控制台来监控不同场景的console.log,这些都是成功的 例如,我在console.log中得到不同的响应: Coginto中存在但密码错误的用户:NotAuthorizedException:错误的用户名或密码。 Cognito中不存在的用户:UserNotFoundException:用户不

我是奥雷利亚的新手,有一些Javascript方面的背景。特别是,我从中汲取灵感,并将两者结合起来

我能够成功地调用AWS Cognito并获得不同的验证结果。我知道,通过在firefox中打开开发者控制台来监控不同场景的console.log,这些都是成功的

例如,我在console.log中得到不同的响应:

Coginto中存在但密码错误的用户:NotAuthorizedException:错误的用户名或密码。 Cognito中不存在的用户:UserNotFoundException:用户不存在。 密码正确的用户:获取JWT令牌 在我的login.html中,我打算通过${loginError}变量显示登录错误

  -- login.html

  <form role="form" submit.delegate="loginUser()">
       ...
       <button type="submit" class="btn btn-default">Login</button>
  </form>
  ...
  <div class="alert alert-danger" >${loginError}</div>
  ...
当this.login错误设置为err时,它不会反映在html中。这可能是因为Javascript中回调函数的性质……我正试图弄清楚如何解决这个问题;假设html需要显示loginError,而实际错误来自authenticateUser中的回调函数。我相信,this.isUserAuthenticated将面临同样的问题

从积极的一面来看,当登录成功时,location.assign'/home';即使this.isUserAuthenticated=true,也不会执行;不会反映在主login.ts中


提前感谢您的帮助

回答我自己的问题,感谢

基本上使用ES6和arrow功能访问此

cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: (result) => {
    console.log(result);
    this.isUserAuthenticated = true;
    location.assign('#/home');  
    },
...
    onFailure: (err) => {
    console.log(err);
    this.loginError = err;
    this.isUserAuthenticated = false;
    }
});
你明白了。使用函数语法时,局部作用域仅限于该函数。当您使用粗箭头=>{}语法时,这将连接到父作用域。
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: (result) => {
    console.log(result);
    this.isUserAuthenticated = true;
    location.assign('#/home');  
    },
...
    onFailure: (err) => {
    console.log(err);
    this.loginError = err;
    this.isUserAuthenticated = false;
    }
});