updateValueAndValidity

updateValueAndValidity

本文介绍了所有子控件的角形式updateValueAndValidity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Angular 4应用中,我有一个带有多个控件的表单.

In my Angular 4 app, I have a form with several controls.

在某些时候,我需要强制更新其有效性,所以我正在这样做:

At some points I need to force the update of their validity, so I'm doing:

this.form.get('control1').updateValueAndValidity();
this.form.get('control2').updateValueAndValidity();
this.form.get('control3').updateValueAndValidity();
// and so on....

然后:

this.form.updateValueAndValidity();

这很好.

但是我想知道是否有更好的方法来完成相同的事情,只需在父窗体上调用一个方法即可.

However I was wondering if there is a better way to accomplish the same thing, by just calling one method on the parent form.

根据其文档,使用updateValueAndValidity()方法:

但就我而言,我需要更新其后代的价值和有效性.这样我就可以摆脱很多代码行.

but in my case I need to update the value and validity of its descendants. So I can get rid of many lines of code.

推荐答案

目前无法使用AbstractControl自身更新AbstractControl的后代(FormGroup,...).也许在将来的版本中是可能的.

It is not possible at the moment to update the descendants of an AbstractControl (FormGroup, ...) with the AbstractControl itself. Maybe in a future release it will be possible.

https://github.com/angular/angular/issues/6170

https://github.com/angular/angular/issues/22166

更新:拉取请求已经打开 https://github.com/angular/angular/pull/19829

update: a pull request is already openhttps://github.com/angular/angular/pull/19829

这篇关于所有子控件的角形式updateValueAndValidity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:37