我目前为我的app项目传递了firebase v3,但我的身份验证系统不起作用,我不明白为什么。这是我的代码:
.controller('loginCtrl', function($scope) {
$scope.loginEmail = function(){
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
});
};
})
.controller('signinCtrl', function($scope) {
$scope.signupEmail = function(){
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
});
};
});
和我的表格:
<form>
<ion-list>
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" placeholder="enter username..." ng-model="data.username">
</label>
<label class="item item-input">
<span class="input-label">Email</span>
<input type="email" placeholder="you@domain.com" ng-model="data.email">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" placeholder="At least 6 characters" ng-model="data.password">
</label>
</ion-list>
<button class="button button-stable button-block" ng-click="signupEmail()">Done</button>
</form>
Chrome控制台会回复此消息:
ReferenceError: email is not defined
有人可以帮助我吗?
答案 0 :(得分:0)
我认为您应该先将可变电子邮件初始化并在其中存储值,然后再将其传递到firebase数据库。同时给它一个id,以便可以选择元素。对密码也一样。
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
<form>
<ion-list>
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" placeholder="enter username..." ng-model="data.username">
</label>
<label class="item item-input">
<span class="input-label">Email</span>
<input id="email" type="email" placeholder="you@domain.com" ng-model="data.email">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input id="password" type="password" placeholder="At least 6 characters" ng-model="data.password">
</label>
</ion-list>
<button class="button button-stable button-block" ng-click="signupEmail()">Done</button>
</form>
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
});