如何在没有表单标签的AngularJS中应用验证?

前端之家收集整理的这篇文章主要介绍了如何在没有表单标签的AngularJS中应用验证?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个div,其中我没有使用表单标签并在ng-click按钮上提交表单但是如何在AngularJS中应用给定字段的验证. @H_404_2@<div ng-controller="AddNewvisaController"> <input type="text" class="form-control" ng-model="visa.requirement"> <select ng-model="visa.country"> <option value="1">abc<option> <option value="2">xyz<option> <option value="3">pqrs<option> </select> <button type="submit" data-ng-click="submitvisa()">Submit</button> </div>

解决方法

如果您真的不想添加表单标记,可以使用“ng-form”指令. @H_404_2@<body ng-controller="MainCtrl"> <div ng-form="myForm"> <input type="text" required ng-model="user.name" placeholder="Username"> <button ng-click="doSomething()" ng-disabled="myForm.$invalid">DO</button> </div> </body>

example

原文链接:https://www.f2er.com/html/225420.html

猜你在找的HTML相关文章