[英]How to make sure angular reactive form setValue/patchvalue is complete
if I set a form value like bellow如果我设置一个像波纹管这样的表单值
this.loadBasicForm.setValue({
loadDirection,
loadSubDirection,
multiPointType,
truckLoadType
});
I have to use setTimeout to make sure that the value is updated.我必须使用 setTimeout 来确保更新该值。
setTimeout(() => {
//do some other action with the changed values.
}
Is there a better way to do this, other than using setTimeout.除了使用 setTimeout 之外,有没有更好的方法可以做到这一点。
setValue(): Sets the value of the FormArray. setValue():设置 FormArray 的值。 We need to pass an array that must match the structure of the control.
我们需要传递一个必须匹配控件结构的数组。 If our array does not match the structure of the control, setValue() will throw error.
如果我们的数组与控件的结构不匹配,setValue() 将抛出错误。
patchValue(): Patches the value of FormArray. patchValue():修补 FormArray 的值。 We need to pass an array that should match the structure of the control.
我们需要传递一个应该匹配控件结构的数组。 If the array that we pass, does not match the structure of the control completely, then patchValue() will patch only those fields which are matching with the structure of the control and rest will be as it is.
如果我们传递的数组与控件的结构不完全匹配,则 patchValue() 将只修补那些与控件结构匹配的字段,其余的将保持原样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.