2016-09-11 26 views
0

我剛剛給了AngularFire一個鏡頭,我正在得到錯誤。

以下是我在我的index.html:

<!-- Angular --> 
    <script src="bower_components/angular/angular.min.js"></script> 

    f<!-- Firebase --> 
    <script src="https://www.gstatic.com/firebasejs/3.3.0/firebase.js"></script> 

    <!-- AngularFire --> 
    <script src="https://cdn.firebase.com/libs/angularfire/2.0.2/angularfire.min.js"></script> 

    <script> 
    // Initialize 
    var config = { 
     apiKey: "mykey", 
     authDomain: "mydomain", 
     databaseURL: "myurl", 
     storageBucket: "mybucket", 
    }; 
    firebase.initializeApp(config); 
    </script> 

這是我主要的應用程序模塊:

angular.module('myApp', [ 
    'firebase', 
    'home', 
    'login_modal', 
    'navbar', 
    'ngAnimate', 
    'ui.bootstrap', 
    'ui.router' 
]); 

這裏是我試圖使用AngularFire與模塊:

angular.module('login_modal', [ 
    'firebase' 
]) 

這裏是它的控制器使用Angular UI Bootstrap模式(AngularFire代碼是一半):

// This just creates the modal instance 
angular.module('login_modal').controller('login_modal_controller', function ($rootScope, $uibModal, $log) { 
    var $ctrl = this; 

    $ctrl.animationsEnabled = true; 

    $rootScope.open_login_modal = function (size) { 
    var modalInstance = $uibModal.open({ 
     animation: $ctrl.animationsEnabled, 
     ariaLabelledBy: 'modal-title', 
     ariaDescribedBy: 'modal-body', 
     templateUrl: 'myModalContent.html', 
     controller: 'ModalInstanceCtrl', 
     controllerAs: '$ctrl', 
     size: size, 
     resolve: { 
     sign_up: function() { 
      return $ctrl.sign_up; 
     } 
     } 
    }); 
    }; 
}); 


angular.module('login_modal').controller('ModalInstanceCtrl', ['$scope', '$firebaseAuth', function($uibModalInstance, $scope, $firebaseAuth) { 
    var $ctrl = this; 

    $ctrl.sign_up = true; 
    $ctrl.email = ''; 
    $ctrl.password = ''; 
    $ctrl.school = ''; 

    // *** error is here: error at $ctrl.auth (login_modal.controller.js:41) 
    $ctrl.auth = function(){ 
    var auth = $firebaseAuth(); 

    $ctrl.firebaseUser = null; 
    $ctrl.error = null; 

    if($ctrl.sign_up){ 
      auth.$createUserWithEmailAndPassword($ctrl.email, $ctrl.password) 
      .then(function(firebaseUser){ 
      alert("User " + firebaseUser.uid + " created successfully!"); 
     }) 
     .catch(function(error) { 
      alert("Error: ", error); 
     }); 
    } 

    else { 
     auth.$signInWithEmailAndPassword($ctrl.email, $ctrl.password) 
     .then(function(firebaseUser){ 
     alert("Signed in as:", firebaseUser.uid); 
     }) 
     .catch(function(error) { 
     alert("Authentication failed:", error); 
     }); 
    }  
    }; 

    $ctrl.cancel = function(){ 
    $uibModalInstance.dismiss('cancel'); 
    }; 
}]); 

請注意,使用vanilla Firebase進行此操作時,此工作正常。

+0

你沒有調用'$ firebaseAuth';你只是把它分配給'auth'屬性。你需要[稱之爲](https://github.com/firebase/angularfire/blob/master/docs/migration/1XX-to-2XX.md#firebaseauth-method-renames--signature-changes)。 – cartant

+0

@cartant對不起,我遺漏了它並更新了我的帖子。它仍然給我錯誤。爲了澄清,你的意思是它應該是'var auth = $ firebaseAuth()',是否正確? – skwny

+1

並且控制器函數的文字數組與參數不匹配 - 還有一個額外的參數,所以'$ scope'和'$ firebaseAuth'都不是您認爲的那些參數。 – cartant

回答

0

請參閱@cartant的評論。內聯構造函數的參數不正確。

相關問題