Angular JS Validation - 如何关闭单个字段的必填
Angular JS Validation - How to turn off required for a single field
如果不满足特定条件,我试图在提交时关闭 Angular 表单中单个输入字段的必需属性。我尝试了以下方法:
form.ChangeCreditCard.$setValidity("required", false);
甚至手动设置字段的 $valid 状态:
form.ChangeCreditCard.$valid = true;
但是字段和表单仍然无效。有什么办法可以通过这种方式关闭对单个字段的验证吗?
ng需要 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. A special
directive for setting required is necessary because we cannot use
interpolation inside required. See the interpolation guide for more
info.
如果不满足特定条件,我试图在提交时关闭 Angular 表单中单个输入字段的必需属性。我尝试了以下方法:
form.ChangeCreditCard.$setValidity("required", false);
甚至手动设置字段的 $valid 状态:
form.ChangeCreditCard.$valid = true;
但是字段和表单仍然无效。有什么办法可以通过这种方式关闭对单个字段的验证吗?
ng需要 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. A special directive for setting required is necessary because we cannot use interpolation inside required. See the interpolation guide for more info.