문제

나는 설정하려고 boolean 변수를 사용하면 사용자에 기록됩니다.

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() 을 얻을:

Catch 되지 않는 형식 오류:정의되지 않은 기능은 없습니다

어떤 아이디어가?

내가 생각하는 것이 최선의 취급 사용자 세션에서 App.ApplicationRoute 이후 루트의 모든 것입니다.이 문제가 발생?

UPDATED:피드백과 함께 여기에는 현재/전체 코드입니다.

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

되고 틀에서 설정한 firebasesimplelogin.한 기능을 사용하여 내부에 생성자 전달해야에서 참조하여'이'의 외부 상황.가장 쉬운 방법은 그것을 변경하여 코드의 기능을 this:

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

다른 팁

먼저 첫:)

에서 언급한 바와 같이 Ember.js 문서:

참고:를 재정의하는 경우 init 을 위한 프레임워크 등과 같은 Ember.을 보거나 Ember.ArrayController, 를 호출해야 합니다 이것이다._super()에서 당신의 init 선언!지 않는 경우,타지 않을 수 있는 기회를 할 중요한 설치 작업,그리고 당신은 참 이상한 행동에 응용 프로그램입니다.

두번째,당신 loggedIn 변수하지 않은 선언이나 인스턴스화하고 따라서 null 뿐만 아니라 귀하의 error 하지만 난 당신은 찢어 코드는 프로젝트의 바이올린을 함께 빠른를 들어,그래서 당신이 할 경우:

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

  init: function() {
      this._super(); // <-- call `this._super()` here

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

모두 예상대로 작동해야 합니다:)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top