我正在通過patchValue從我的組件更新一個反應FormGroup
控制值。Angular2:你如何通過`patchValue()標記FormGroup控件髒
例:
this.myForm.patchValue({incidentDate:'2016-09-12');
這個偉大的工程,並觸發valueChanges
事件,但這種控制的dirty
屬性仍然false
。
我需要incidentDate
控制爲dirty
,所以我的驗證邏輯知道要對此控件運行。
如何更新從我的部件的控制的價值,並表明它是髒的?
這裏是我的驗證邏輯:
onValueChanged(data?: any) {
if (!this.myForm) {
return;
}
const form = this.myForm;
for (const field in this.formErrors) {
// clear previous error message (if any)
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.dirty && !control.valid) {
const messages: any = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] + ' ';
}
}
}
}
你是我的朋友,是男人。好奇,你在哪裏發現這個記錄?這是沒有在https://angular.io/docs/ts/latest/api/forms/index/FormControl-class.html被發現在那裏 – rynop
我很經常來到這裏https://github.com/angular/angular /blob/master/modules/%40angular/forms/src/model.ts lol –
當人們直接將我帶入源代碼時,我喜歡它。 – Hinrich