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进行此操作时,此工作正常。
你没有调用'$ firebaseAuth';你只是把它分配给'auth'属性。你需要[称之为](https://github.com/firebase/angularfire/blob/master/docs/migration/1XX-to-2XX.md#firebaseauth-method-renames--signature-changes)。 – cartant
@cartant对不起,我遗漏了它并更新了我的帖子。它仍然给我错误。为了澄清,你的意思是它应该是'var auth = $ firebaseAuth()',是否正确? – skwny
并且控制器函数的文字数组与参数不匹配 - 还有一个额外的参数,所以'$ scope'和'$ firebaseAuth'都不是您认为的那些参数。 – cartant