【问题标题】:Firebase createAuth credentials aren't working with ng-model scope variablesFirebase createAuth 凭据不适用于 ng-model 范围变量
【发布时间】:2015-10-13 05:09:18
【问题描述】:

我第一次在 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 方法的某些内容?

【问题讨论】:

    标签: angularjs ionic-framework angularfire firebase-authentication


    【解决方案1】:

    如果其他人遇到这个问题,这是一个简单的解决方法!我只需要将用于电子邮件和密码的$scope 变量转换为用户对象,即可使用user.email 访问它们。此状态有一个冲突的子范围。

    【讨论】:

      猜你喜欢
      • 2016-11-18
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多