当显示其他错误消息时,是否有可能隐藏错误消息?

时间:2017-07-05 09:26:08

标签: html angularjs

 <form name="form">
     <input type="password" placeholder="Password" ng-model="password" name="password" minlength="6"  maxlength="15" ng-pattern="/^\S*$/" required>
     <span ng-show="form.password.$dirty && form.password.$invalid">
       <span ng-show="form.password.$error.required">Password is required.</span>
       <span ng-show="form.password.$error.minlength">Password should have atleast 6 characters.</span>
       <span ng-show="form.password.$error.pattern">White Space not allowed.</span>
     </span>
 </form>

在此代码中,如果我输入少于6个字符的空格,则表示&#34;密码应至少包含6个字符。&#34; &安培; &#34;不允许使用空格。&#34;

我不想同时显示错误消息,只显示一条错误消息。

1 个答案:

答案 0 :(得分:1)

如果满足这两个条件,您需要决定显示哪一个。

<span ng-show="form.password.$error.minlength">Password should have atleast 6 characters.</span>
<span ng-show="form.password.$error.pattern && !form.password.$error.minlength">White Space not allowed.</span>

如果你有第三个

<span ng-show="form.password.$error.patternQ 
    && !form.password.$error.pattern 
    && !form.password.$error.minlength">Question mark not allowed.</span>