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

Sus*_*hra 6 angularjs

我有一个div,其中我没有使用表单标签并在ng-click按钮上提交表单但是如何在AngularJS中应用给定字段的验证.

<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>
Run Code Online (Sandbox Code Playgroud)

小智 15

如果您真的不想添加表单标记,可以使用"ng-form"指令.

<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>
Run Code Online (Sandbox Code Playgroud)