加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs:ng消息总是显示

发布时间:2020-12-17 08:08:32 所属栏目:安全 来源:网络整理
导读:我使用角度消息在我的角度应用程序上显示表单验证错误。 根据文档,我已经构建了以下代码 form name="loginForm" label class="item item-input" input type="email" placeholder="Email" ng-model="data.email" name="email" required /label div ng-messag
我使用角度消息在我的角度应用程序上显示表单验证错误。
根据文档,我已经构建了以下代码
<form name="loginForm">
  <label class="item item-input">
    <input type="email" placeholder="Email" ng-model="data.email" name="email" required>
  </label>
  <div ng-messages="loginForm.email.$error" style="color:maroon">
    <div ng-message="required">Please input a valid e-mail address</div>
    <div ng-message="email">You did not enter your email address correctly...</div>
  </div>
</form>

我在我的javascript中包含了ngMessages指令,并导入了angular-messages.js文件。

不幸的是,这两个消息永远显示出来。不管输入字段中输入什么,无论是否是有效的电子邮件。这两个消息总是显示。如果我只尝试一个ng消息,结果是一样的。

任何想法我可能做错了什么?

编辑:如果我的描述不是很清楚,这是打印的结果
http://s9.postimg.org/du9230tdb/Screen_Shot_2015_06_26_at_17_09_24.png

一切似乎都在您正在分享的代码中。
<form name="loginForm">
    <label class="item item-input">
        <input type="email" placeholder="Email" ng-model="data.email" name="email" required>
    </label>
    <div ng-messages="loginForm.email.$error" style="color:maroon">
        <div ng-message="required">Please input a valid e-mail address</div>
        <div ng-message="email">You did not enter your email address correctly...</div>
    </div>
</form>

Here is a working copy on Plunker我正在使用你的代码。

从Angularjs documentation。

By default,ngMessages will only display one error at a time. However,if you wish to display all messages then the ng-messages-multiple attribute flag can be used on the element containing the ngMessages directive to make this happen.

如果您想要在字段变脏后显示错误,请访问此link。

确保您还包括ngMessage模块和库。请参阅Carlos’s answer。

谢谢

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读