TypeError:$ firebaseAuth不是函数

时间:2016-09-11 15:06:04

标签: angularjs firebase angularfire firebase-authentication

我刚刚给了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进行此操作时,这是有效的。

1 个答案:

答案 0 :(得分:0)

请参阅@cartant的评论。我的内联构造函数的参数不正确。