且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法读取未定义的属性“navCtrl"

更新时间:1970-01-01 07:57:12

解决此问题的更好方法是使用 箭头函数:

A better way to solve this issue would be by using arrow functions:

箭头函数表达式的语法比函数短表达式并且不绑定它自己的 this、arguments、super 或新目标.

An arrow function expression has a shorter syntax than a function expression and does not bind its own this, arguments, super, or new.target.

所以你的问题可以通过像这样改变 onSignIn 方法来解决:

So your issue would be solved by just changing the onSignIn method like this:

  onSignIn() {
    firebase.auth().signInWithPopup(provider).then((result) => {
      console.log(result.credential.accessToken);
      console.log(result.user.displayName);
      this.navCtrl.setRoot(HomePage);
    }).catch(function(error) {
      console.log(error.message);
    });
  }

注意 (result) =>{...} 而不是 function(result) {...}