[英]Angular JS Validation - How to turn off required for a single field
I'm trying to turn off the required attribute for a single input field in an Angular form on submit, if a certain condition is not met. 如果不满足特定条件,我将在提交时关闭Angular表单中单个输入字段的必需属性。 I have tried the following:
我尝试了以下方法:
form.ChangeCreditCard.$setValidity("required", false);
And even manually setting the $valid state for the field: 甚至手动为该字段设置$ valid状态:
form.ChangeCreditCard.$valid = true;
But the field and thus the form is still invalid. 但是字段和表格仍然无效。 Is there any way I could turn off validation on a single field in this way?
有什么办法可以以这种方式在单个字段上关闭验证吗?
ngRequired https://docs.angularjs.org/api/ng/directive/ngRequired ngRequired https://docs.angularjs.org/api/ng/directive/ngRequired
The directive sets the required attribute on the element if the Angular expression inside ngRequired evaluates to true.
如果ngRequired中的Angular表达式的值为true,则指令将在元素上设置required属性。 A special directive for setting required is necessary because we cannot use interpolation inside required.
必须设置一个特殊的指令,因为我们不能在required内部使用插值。 See the interpolation guide for more info.
有关更多信息,请参见插值指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.