Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用ng maxlength时显示错误消息_Html_Angularjs_Twitter Bootstrap - Fatal编程技术网

Html 使用ng maxlength时显示错误消息

Html 使用ng maxlength时显示错误消息,html,angularjs,twitter-bootstrap,Html,Angularjs,Twitter Bootstrap,当我的登录名达到最大限制32时,我试图显示一条错误消息。以前粘贴的代码是我通常使用的,但由于某种原因它不起作用。唯一的区别是,我没有使用模式框,只是使用文本框,如果这可能是问题所在?谢谢大家! <form class="form-horizontal" name="myForm"> <fieldset> <div class="form-group"

当我的登录名达到最大限制32时,我试图显示一条错误消息。以前粘贴的代码是我通常使用的,但由于某种原因它不起作用。唯一的区别是,我没有使用模式框,只是使用文本框,如果这可能是问题所在?谢谢大家!

  <form class="form-horizontal" name="myForm">
                        <fieldset>
                            <div class="form-group"
                                 ng-class="{ 'has-error' : myForm.loginName.$invalid && !myForm.loginName.$pristine }">
                                <label class="col-lg-4 col-sm-4 col-xs-4 control-label no-padding-right">Login
                                    Name</label>
                                <div class="col-lg-6 col-sm-6 col-xs-6">
                                    <input type="text" class="form-control"
                                           id="loginName" name="loginName"
                                           ng-model="targetEntity.loginName" required placeholder="Login Name"
                                           ng-maxlength="32">
                                    <p ng-show="myForm.loginName.$invalid && !myForm.loginName.$pristine"
                                       class="help-block">Mandatory field, maximum length 255 characters.</p>
                                </div>
                            </div>
                         </fieldset>
 </form>
您必须使用$error


您还可以更直接地使用它,因为$error是angular提供的对象。例如,下面的方法:

ng-show="myForm.loginName.$error.maxlength"

但我建议使用前面提到的ngMessages,因为它更简单。

您只检查错误消息中的无效和原始信息。您需要检查输入中的字符计数,将其设置为最大长度不会使其无效。那么,我必须输入什么?
ng-show="myForm.loginName.$error.maxlength"