如何在角JS应用验证,而不表单标签? [英] how to apply validation in angular js without form tag?

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

问题描述

我在哪,我不使用形式标记和提交表单的div NG单击按钮,但如何申请在给定angulrjs提交的验证。

 < D​​IV NG控制器=AddNewvisaController>
<输入类型=文本级=表格控NG模型=visa.requirement>
 <选择NG模型=visa.country>
  <期权价值=1> ABC<选项>
    <期权价值=2>&XYZ LT;选项>
     <期权价值=3>&PQRS LT;选项>
< /选择>
<按钮式=提交数据-NG-点击=submitvisa()>提交< /按钮>
< / DIV>


解决方案

您可以使用NG-形式指令,如果你真的不想要添加一个表单标签。

 <机身NG控制器=MainCtrl>
  < D​​IV NG型=myForm会>
    <输入类型=文本要求NG-模式=user.name占位符=用户名>
    <按钮NG点击=DoSomething的()NG-禁用=myForm会$无效的。> DO< /按钮>
  < / DIV>
< /身体GT;

例如

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

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

解决方案

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>

example

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

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