且构网

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

无法读取未定义的属性'navCtrl'

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

A解决此问题的更好方法是使用箭头功能

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


箭头函数表达式的语法比函数
表达式短,并且不绑定它自己的, arguments,super或
new.target。

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);
    });
  }

注意(结果)=> {...} 而不是函数(结果){...}