AngularJS&LT;输入&GT;验证没有封闭&LT;形式为GT; [英] AngularJS <input> validation with no enclosing <form>
本文介绍了AngularJS&LT;输入&GT;验证没有封闭&LT;形式为GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在角度来验证一个单一的,孤立的&LT;输入&GT;
以类似的方式在形式验证?我想是这样的:
Is it possible in Angular to validate a single, isolated <input>
in a similar way the forms are validated? I'm thinking about something like this:
<div class="form-group">
<input name="myInput" type="text" class="form-control" ng-model="bindTo" ng-maxlength="5">
<span class="error" ng-show="myInput.$error.maxlength">Too long!</span>
</div>
上面的例子不工作。在封闭它&LT;形式&GT;
和替换 NG-节目
与 NG-秀= myForm.myInput。$ error.maxlength
帮助。
是否有可能做到这一点,而无需使用&LT;形式为GT;
Is it possible to do this without using <form>
?
推荐答案
您可以使用NG形式的角度指令(的看到文档这里)进行分组任何东西,甚至外的HTML表单。然后,您可以利用从角的FormController。
You may use the ng-form angular directive (see docs here) to group anything, even outside a html form. Then, you can take advantage from angular FormController.
<div class="form-group" ng-form name="myForm">
<input name="myInput" type="text" class="form-control" ng-model="bindTo" ng-maxlength="5">
<span class="error" ng-show="myForm.myInput.$error.maxlength">Too long!</span>
</div>
这篇关于AngularJS&LT;输入&GT;验证没有封闭&LT;形式为GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文