使用Angular 2+进行键入和擦除后,检测反应表单是否不再脏



很容易检测表单何时更改和变脏:

ngAfterViewInit() {
this.form.valueChanges.subscribe(() => {
console.log(this.form.dirty);
});
}

但现在我需要知道表单的某个字段何时被擦除和清除,并将表单改回不脏的状态。

您可以这样做:

// To remove the control
if (this.form.get('controlName')) {
this.form.removeControl('controlName');
this.form.updateValueAndValidity();
}

最新更新