2016-06-24 27 views
1

嘗試驗證使用Firebase的用戶。使用firebase 2.xx啓動我的應用程序,但即使升級到Firebase 3.xx後,拋出 錯誤「onAuthStateChanged不是函數」。驗證狀態已更改AngularFire

這是我的登錄功能,外觀喜歡 -

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

回答

2

你的問題是,你傳遞一個$firebaseObject$firebaseAuth()

因此,請確保您正在初始化您的[$firebaseAuth][1]對象,如下所示,然後您的代碼應該正常工作。

var loginObj = $firebaseAuth(); 

工作jsFiddle用於演示。

您可以在這裏查看的文件AngularFire2