我第一次在 Ionic 项目中使用 AngularFire。我按照firebase网站上的文档中的示例使用电子邮件和密码进行身份验证。由于某种原因,我来自ng-model的$scope值没有正确绑定。
angular.module('starter')
.controller('RegisterController', ['Auth', '$scope', function(Auth, $scope) {
$scope.createUser = function() {
$scope.message = null;
$scope.error = null;
Auth.$createUser({
email: $scope.email,
password: $scope.password
})
.then(function(userData) {
$scope.message = "User created: ";
})
.catch(function(error) {
$scope.error = error;
});
};
}]);
如果我用$scope.email
硬编码的电子邮件和密码替换 $scope.password ,它就可以工作。这是包含电子邮件和密码模型数据的模板。
<ion-view view-title='Register A New Account' hide-back-button="false">
<ion-content class='padding'>
<div class="list list-inset">
<label class='item item-input'>
<span class='input-label'>Email</span>
<input type="text" placeholder='example@email.com' ng-model="email">
</label>
<label class='item item-input'>
<span class='input-label'>Password</span>
<input type="password" placeholder='' ng-model='password'>
</label>
<label class='item item-input'>
<span class='input-label'>Cell Phone</span>
<input type="tel" placeholder='316-333-3333'>
</label>
<label class='item item-input'>
<span class='input-label'>Date of Birth</span>
<input type="date">
</label>
<label class='item item-input'>
<span class='input-label'>City</span>
<input type="number" placeholder='Wichita'>
</label>
<label class='item item-input'>
<span class='input-label'>State</span>
<input type="number" placeholder='Kansas'>
</label>
<label class='item item-input'>
<span class='input-label'>Zipcode</span>
<input type="number" placeholder='67208'>
</label>
</div>
<ion-checkbox>
I agree to terms and conditions
</ion-checkbox>
<button class='button button-block button-calm' ng-click='createUser()'>Login</button>
<p ng-if='message'>Message: {{message}}</p>
<p ng-if='error'>Error: {{error}}</p>
</ion-content>
</ion-view>
我的 $scope 值设置错误还是我缺少关于 createAuth 方法的某些内容?