javascript - $authWithPassword 不是 AngularFire 2.x 中的函数

标签 javascript angularjs firebase angularfire firebase-authentication

我以前看过有关此问题的帖子,但它们要么已经过时,要么提供与我的设置非常相似的解决方案。

基本上,我的 Controller 中有两个函数:authCtrl.login 和 authCtrl.register。寄存器对 Auth.$createUserWithEmailAndPassword() 的调用工作正常,但登录对 Auth.$authWithPassword() 的调用则不然,因为我收到“..不是函数”错误。我一生都无法弄清楚这里出了什么问题。

这是我的设置:

auth.service.js:

angular.module('angularfireSlackApp')
.factory('Auth', function($firebaseAuth, $firebaseObject){
var auth = $firebaseAuth();

return auth;
});

auth.controller.js:

angular.module('angularfireSlackApp')
.controller('AuthCtrl', function(Auth, $state){
var authCtrl = this;

authCtrl.user = {
  email: '',
  password: ''
};

authCtrl.login = function() {
// Why is this not a function
Auth.$authWithPassword(authCtrl.user)
.then(function (auth){
  $state.go('home');
}, function (error){
  authCtrl.error = error;
});
}

authCtrl.register = function() {
Auth.$createUserWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password)
.then(function (user){
  authCtrl.login();
}, function (error){
  authCtrl.error = error;
});
}

});

最佳答案

关于javascript - $authWithPassword 不是 AngularFire 2.x 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38670049/

相关文章:

php - 目录内容更改时刷新页面

javascript - 工厂和 Controller 依赖错误

java - 使用 Firebase-UI (Android) 的 Firestore 聊天应用

android - Firebase 邀请发送电子邮件但不发送短信。返回结果代码 0

javascript - 在 Java 中使用 HTTPClient 下载文件

javascript - 如何添加直到稍后才被解析的 HTML 元素?

javascript - mxGraph:来自外部按钮的单击事件

javascript - 如何防止刷新页面后重新加载整个 ng-admin

javascript - angular.element ('#home' )返回未定义

firebase - 如何更改现有 Firebase 项目的区域?