【问题标题】:Form validation using ngMessage showing error on load only使用 ngMessage 的表单验证仅在加载时显示错误
【发布时间】:2016-07-18 09:22:17
【问题描述】:

这是我的表格

我的行为很奇怪。当我的表单加载时,当页面只加载任何内容时,这将向您显示“这是必需的”错误。 当我输入一些东西时,消息不会消失它只会在那里。

<form name="myForm">
  <md-input-container class="md-icon-float md-block">
  <label>{{controlObject.controlValue}}</label>
  <md-icon md-font-icon="" aria-label="{{controlObject.controlValue}}"></md-icon>
  <input type="text" ng-model="controlObject.controlAttribute" name="{{controlObject.controlId}}" ng-required="true">
  <div ng-messages="myForm.{{controlObject.controlId}}.$error" layout-align="end end" layout="column">
    <div ng-message="required" ng-if="myForm.$pristine">This is required.</div>
  </div>

我不知道我在这里做错了什么。请告诉我如何解决。

【问题讨论】:

    标签: angularjs forms validation ng-messages


    【解决方案1】:

    您可以在$dirty$submitted 上使用ng-show

    <div ng-show="myForm.{{controlObject.controlId}}.$dirty" ng-messages="myForm.{{controlObject.controlId}}.$error" layout-align="end end" layout="column"> <div ng-message="required" ng-if="myForm.$pristine">This is required.</div> </div>

    【讨论】:

    • 不工作 .. 仍然错误消息仅在页面加载时可见
    • 你能做个小插曲吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2018-09-03
    • 2014-10-27
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多