且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular2-如何将窗体上的`touched`属性设置为true

更新时间:2023-10-09 17:37:16

有一个非常简单的方法可以做到这一点:markAsTouched.在表单组上使用它就足够了.

There's a pretty straightforward method to do this: markAsTouched. It should be enough to use it on the form group.

this.addressForm.markAsTouched()

如果您出于某种原因想要手动标记所有控件,则它们本身都可以使用此方法.

In case you want for some reason to mark all controls manually, they itself have this method available.

markAsTouchedAbstractControl所有表单元素所继承的方法.出于好奇,您可能想访问@angular/forms/src/model.d.ts声明文件,以找到表单对象的一些更有趣的方法.或只需访问文档.

markAsTouched is a method of the AbstractControl all form elements inherit from. Out of curiosity, you might want to visit the @angular/forms/src/model.d.ts declaration file to find some more interesting methods of the form objects. Or just visit the documentation.