2016-06-24 9 views
1

Der Versuch, einen Benutzer mit Firebase zu authentifizieren. Starte meine App mit Firebase 2.xx, aber selbst nach dem Upgrade auf Firebase 3.xx, werfen Fehler "OnAuthStateChanged ist keine Funktion". DieseOn Auth State geändert AngularFire

ist, wie meine Login-Funktion sieht wie-

.controller('HomeCtrl', ['$scope','$location','CommonProp','$firebaseAuth', '$firebaseObject',function($scope,$location,CommonProp,$firebaseAuth,$firebaseObject) { 

    var firebaseObj = $firebaseObject(rootRef); 
    var loginObj = $firebaseAuth(firebaseObj); 

    $scope.SignIn = function($scope, user) { 
    event.preventDefault(); // To prevent form refresh 
    var username = user.email; 
    var password = user.password; 


    loginObj.$signInWithEmailAndPassword({ 
      email: username, 
      password: password 
     }) 
     .then(function(user) { 
      // Success callback 
      console.log('Authentication successful'); 
      $location.path("/welcome"); 
      CommonProp.setUser(user.password.email); 
     }, function(error) { 
      // Failure callback 
      console.log(error); 
     }); 
} 
}]); 

Antwort

2

Ihr Problem ist, dass Sie eine $firebaseObject-$firebaseAuth() sind vorbei.

So stellen Sie sicher, dass Sie Ihr [$firebaseAuth][1] Objekt wie folgt initialisieren, und dann sollte Ihr Code ordnungsgemäß funktionieren.

var loginObj = $firebaseAuth(); 

Arbeiten jsFiddle zum Demonstrieren.

können Sie prüfen, hier in der Dokumentation zu AngularFire2

Verwandte Themen