trackFormChanges() {
this.form.valueChanges.pipe(
debounceTime(300),
distinctUntilChanged())
.subscribe(data => {
setTimeout(() => {
if (this.form.dirty && this.form.touched) { //dirty works but touched property has old value
this.prompt = true;
}
if (this.recordCopy) {
if (_.isEqual(this.record, this.recordCopy)) {
this.isSaved = true;
} else {
this.successes = [];
this.isSaved = false;
}
}
}, 500);
});
}
我正在尝试检查是否在触发valueChanges时触摸了表单,form.dirty
有效,但form.touched
为假并且不更新,我不想订阅form.statuschanges
,更多的超额更改会触发多次。有办法解决吗?
这是FormGroup的实现,如果您触摸控件,它不会触摸父FormGroups-仅会触摸该控件。
甚至还有form.statuschanges
也不会在触摸时作出反应,仅在相关的FormGroup / FormControl变为有效/无效时才发光。
在您的情况下,您需要重新考虑使用form.touched
以避免它,或者添加一个额外的逻辑来触摸父FromGroup,但是子控件没有指向其父控件的指针。