Ionic-来自电子邮件框的数据返回未定义

Ionic - data from email box returning undefined

本文关键字:数据 返回 未定义 电子邮件 Ionic-      更新时间:2023-09-26

我写了一段代码,使用带有firebase的Ionic Framework创建了一个用户帐户,但由于某种原因,电子邮件框返回了一个未定义的密码框,而密码框工作正常-两者的方式几乎相同。这是我的HTML:

<ion-view view-title="Create Account">

<form name="form" novalidate="" ng-submit="createUser(form)">
  <div class="list">
    <label class="item item-input">
      <span class="input-label">Email:</span>
      <input type="text" ng-name = "email" ng-model="form.email" ng-minlength="5" ng-maxlength="20" required>
    </label>
    <div class="error-container">
      <div ng-messages-include="error-list.html"></div>
    </div>
    <label class="item item-input">
      <span class="input-label">Password</span>
      <input type="password" ng-name = "password" ng-model="form.password" ng-minlength="5" ng-maxlength="20" required>
    </label>
    <div class="error-container last-error-container">
        <div ng-messages-include="error-list.html"></div>
    </div>
  </div>
  <button class="button button-full button-positive" type="submit">
      Create Account
    </button>
</form>

这是控制器类-当表单提交时,视图在控制器中调用此函数:

  $scope.createUser = function(form) {
console.log("Email: " + form.email);
console.log(form.password);
var information = {
  email: form.email,
  password: form.password
};
Settings.createUser(form.email, form.password);

};

正如你所看到的,我有两个console.log。第一个总是返回"电子邮件:未定义",第二个返回我键入的任何密码,所以密码有效,但电子邮件输入框无效。对Settings.createUser的调用随后失败,因为未定义电子邮件。

我错过了什么?

提前谢谢。

在$scope.createUser函数中,尝试访问这样的元素,

this.email
this.password

而不是CCD_ 1和CCD_。这里有一个链接到一个plunker,我认为它可以实现你想要的。此外,请查看表单上的AngularJS文档,其中有一些很好的信息可以帮助您。

http://plnkr.co/edit/1ZFvLHLSXgkqQVNHCGMb?p=preview

https://docs.angularjs.org/guide/forms

OH-我想好了。。。它是ng最大长度="20"。我意识到如果我打字asdf@hotmail.com它会接受它,但不会接受我测试它的输入mattang5280@hotmail.com"。原因是因为第二个字符超过20个字符,因此它将返回undefined。