【发布时间】:2021-04-15 00:35:51
【问题描述】:
有这样的形式:
this.form = this.fb.group({
name: [null, [Validators.required]],
companyHolderUid: [null],
generalDescription: [null],
authority: [TemplateAuthorities.Root],
tabs: this.fb.array([]),
tagReferences: this.fb.array([]),
}, { updateOn: 'blur' });
我想在不触发 valueChanges 的情况下更新 tabs 或 tagReferences。像这样的东西
{ emitEvent: false, onlySelf: true }
当使用 patchValue 并尝试控制台时 tabs 为空
private formInit(template: AssetTemplate) {
this.form.patchValue({
name: template.name,
companyHolderUid: template.companyHolderUid,
generalDescription: template.generalDescription,
authority: template.authority,
tabs: [1,2,3,4]
}, { emitEvent: false, onlySelf: true });
console.log(JSON.stringify(this.form.value));
}
console.log 结果:
{
"name":"test template",
"companyHolderUid":null,
"generalDescription":"Lorem ipsum",
"authority":"ROOT",
"tabs":[],
"tagReferences":[]
}
【问题讨论】:
标签: angular angular-reactive-forms formarray