質問

ユーザーがログインしているときはいつでもブール変数を設定しようとしています。

App.ApplicationRoute = Ember.Route.extend({
  isLoggedIn: false,

  init: function() {
      if (loggedIn) {
        this.set('isLoggedIn', true);
      } else {
        console.log(error)
        this.set('isLoggedIn', false);
      }
    });
  }
});
.

しかし、this.set()でGet:

アカウントのTypeError:未定義は関数ではありません

任意のアイデア?

私はユーザーセッションを処理するための最良の場所がすべてのものの根以来、App.ApplicationRouteにあると考えました。これは問題を引き起こしますか?

更新: フィードバックでは現在/フルコードがあります。

App.ApplicationRoute = Ember.Route.extend({
  isLoggedIn: false,

  init: function() {
    this._super();

    auth = new FirebaseSimpleLogin(appRef, function(error, user) {
      if (user) {
        console.log(user)
        this.set('isLoggedIn', true);
      } else {
        console.log(error)
        this.set('isLoggedIn', false);
      }
    });
  }
})
.

だから私は本当にそれが関連性があると思ったのではなく、問題を追跡するために、私はそれを追加しました。

役に立ちましたか?

解決

理由は

と関係がある必要があります
this
.

あなたのFirebaseImpleginに間違って設定されています。コンストラクタの内側を使用している関数は、外部コンテキストの「これ」への参照で渡されなければなりません。これを行う最も簡単な方法は、これに関数のコードを変更することです。

function(error, user) {
  if (user) {
    console.log(user)
    this.set('isLoggedIn', true);
  } else {
    console.log(error)
    this.set('isLoggedIn', false);
  }
}.bind(this));
.

他のヒント

最初のものは最初のもの:)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top