为AngularJS中的无效输入字段实现错误类



首先是我的html代码:

<form name="Form" novalidate>
   <div class="form-group has-error has-feedback">
      <input class="form-control" type="text" name="Name" ng-model="item.name" required="" aria-describedby="" />
      <span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>
      <span class="sr-only">(error)</span>
      <br />
      <div class="has-error has-feedback" ng-show="Form.$submitted || Form.Name.$touched">
         <span ng-show="Form.Name.$error.required">Name is invalid.</span>
      </div>
   </div>

我只想在名称无效时展示" Has-Error has-orror has-feedback"和glyphicon。我该如何开发?

如果要根据它的显示无效,则需要执行此操作:

<div class="has-error has-feedback" ng-show="Form.Name.$invalid">
     <span ng-show="Form.Name.$error.required">Name is invalid.</span>
</div>

同样的glyphicon:

<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" ng-show="Form.Name.$invalid"></span>

最新更新