有什么要求和NG-所需之间的区别? [英] What is the difference between required and ng-required?

查看:105
本文介绍了有什么要求和NG-所需之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么要求 NG-要求(表单验证)?

What is the difference between required and ng-required (form validation)?

推荐答案

AngularJS的表单元素查找所需的属性来执行验证功能。 NG-需要让你依赖于布尔测试设置所需的attibute(例如,只需要场B - 也就是说,一个学号的 - 如果字段A具有一定的价值 - 的如果您选择学生作为一种选择的)

AngularJS form elements look for the required attribute to perform validation functions. ng-required allows you to set the required attibute depending on a boolean test (for instance, only require field B - say, a student number - if the field A has a certain value - if you selected "student" as a choice)

作为一个例子,<要求输入> <输入NG-所需=真> 在本质上是一样的东西

As an example, <input required> and <input ng-required="true"> are essentially the same thing

如果你想知道的为什么这是这样,(而不仅仅是让&LT;必需=真正的&GT输入; &LT;输入所需=FALSE&GT; ),这是由于HTML的限制 - 要求属性有没有相关的价值 - 它仅仅是presence手段(按照HTML标准),该元素是必需的 - 这样的角度需要一种方法来设置/取消要求值(所需=FALSE将是无效的HTML)

If you are wondering why this is this way, (and not just make <input required="true"> or <input required="false">), it is due to the limitations of HTML - the required attribute has no associated value - it's mere presence means (as per HTML standards) that the element is required - so angular needs a way to set/unset required value (required="false" would be invalid HTML)

这篇关于有什么要求和NG-所需之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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