将值重置为补丁值后的状态

时间:2018-11-02 16:00:44

标签: angular

我有一个基本的表单设置:

this.myForm = this.fb.group({
            name: [null]
        });

然后我修补值:

this.myForm.controls['name'].patchValue("Andrew");

我有一个重置按钮,但我希​​望在修补该值后 后,它返回到状态。因此,例如,如果我将名称更改为“ Brian”,然后单击“重置”按钮,则希望它返回到“ Andrew”。 其他帖子说过使用:

this.myForm.reset(this.myForm.value);

但这似乎不起作用。

如果我使用:

this.myForm.reset();

它只是将所有内容设置为空白。

0 个答案:

没有答案