【问题标题】:Angularjs - after I enter a value into a <intput> field with ng-model the value changes to undefinedAngularjs - 在我使用 ng-model 在 <input> 字段中输入一个值后,值更改为 undefined
【发布时间】:2014-10-12 11:31:51
【问题描述】:

我有一个接受输入的简单表单。出于某种原因,当我更改值时,范围变量会更改为 undefined。

<body ng-controller="myctrler">
<input ng-model="t.unsubscribeEmail" type="email" class="textboxfields" placeholder="Enter email address">
</body>

在控制器中:

$scope.k=
{
    unsubscribeEmail : "not"
};

我在输入框中输入任何内容之前的值是“not”。只要我在输入中输入内容,值就会变为未定义。

我错过了什么?

【问题讨论】:

  • 该值无效(不是电子邮件地址),因此型号为undefined。试试not@example.com 看看有什么不同。
  • 废话,我想这对我来说太早了。我没有考虑验证。谢谢

标签: angularjs angular-ngmodel


【解决方案1】:

更改您的输入类型文本或编写验证电子邮件

<input ng-model="t.unsubscribeEmail" type="text" class="textboxfields" placeholder="Enter email address">

或写验证电子邮件

<input ng-model="t.unsubscribeEmail" type="email" class="textboxfields" placeholder="Enter email address">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 2018-09-30
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    相关资源
    最近更新 更多