如何在没有表单标记的情况下在AngularJS中应用验证?

如何在没有表单标记的情况下在AngularJS中应用验证?,angularjs,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"&g

我有一个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>

abc
xyz
pqrs
提交
如果确实不想添加表单标记,可以使用“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>

你可以试试下面的东西

var myValidationModule=angular.module('myApp',[]);
myValidationModule.controller('AddNewvisaController',函数($scope){
$scope.visa={要求:,国家:“pqrs”}
//initilize为false-它将确保禁用提交按钮
$scope.enableSubmitButton=false;
//进行手表收集-无论何时发生更改,都会触发此操作,然后根据需要进行验证-此处我验证为非空-您可以根据自己的意愿执行任何操作,如果一切正常,则启用按钮
$scope.$watchCollection(['requirement,country'],函数(valueArray){
如果(valueArray[0]!=“”&valueArray[1]!=“”){
$scope.enableSubmitButton=true;
}否则{
$scope.enableSubmitButton=false;
}
})
})

abc
xyz
pqrs

提交您是否查看了示例链接?它对你不起作用吗?Himn尝试了你的url,但当我用下面的代码修改时它不起作用