如何在不带表单标签的AngularJS中应用验证? [英] how to apply validation in AngularJS without form tag?

查看:82
本文介绍了如何在不带表单标签的AngularJS中应用验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a div in which I am not using the form tag and submit the form on ng-click button but how can I apply the validation of given filed in 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>

推荐答案

如果您确实不想添加表单标签,则可以使用"ng-form"指令.

You can use the "ng-form" directive if you really dont want to add a form tag.

<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>

示例

这篇关于如何在不带表单标签的AngularJS中应用验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆