【发布时间】:2016-04-08 23:53:18
【问题描述】:
我创建了一个用户登录模板。我想用 firebase 注册用户。
我收到以下错误。
错误:Firebase.createUser 失败:第一个参数必须包含类型为“string”的键“email” 在错误(本机)
我的控制器
.controller('LoginCtrl', ['$firebaseAuth','$scope','$timeout','$stateParams',function($firebaseAuth,$scope, $timeout, $stateParams) {
console.log("Login Control");
$scope.signupEmail = function() {
var ref = new Firebase("https://requestmaker.firebaseio.com");
ref.createUser({
email: $scope.email,
password: $scope.password
}, function(error, userData) {
if (error) {
console.log("Error creating user:", error);
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
};
}]);
..在我的 index.html 文件中,我已经包含了
<!-- firebase.js -->
<script src="https://cdn.firebase.com/js/client/2.3.2/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.2/angularfire.min.js"></script>
..在我的离子视图模板中
<button class="button button-full button-assertive" ng-click="signupEmail()">Login</button>
有人请告诉我我哪里错了。
回答
.controller('SignInCtrl', function ($scope, $rootScope, $state, $ionicHistory, Auth, UserData, $firebase) {
$scope.hideBackButton = true;
/* FOR DEV PURPOSES */
$scope.user = {
email: "",
password: ""
};
$scope.signIn = function (user) {
$rootScope.show('Logging In...');
/* Check user fields*/
if(!user.email || !user.password){
$rootScope.hide();
$rootScope.notify('Error','Email or Password is incorrect!');
return;
}
/* All good, let's authentify */
Auth.$authWithPassword({
email : user.email,
password : user.password
}).then(function (authData) {
console.log(authData);
$rootScope.hide();
}).catch(function (error) {
$rootScope.hide();
$rootScope.notify('Error','Email or Password is incorrect!');
});
};
谢谢, 萨巴里斯里
【问题讨论】:
-
$scope.email 的值是多少?
-
@AndréKool 这是我的 template.html 中的一个范围变量
-
可以在设置邮箱和密码的地方添加代码吗?我认为他们没有正确的类型,因为错误是说你需要一个字符串类型的电子邮件。