我有一个简单的
FormGroup
:
const formGroup = this.formBuilder.group({
general: this.formBuilder.group({
description: [job.description],
country: [job.country],
nextRun: [job.nextRun],
lastRun: [job.lastRun],
enabled: [job.enabled],
tags: [this.jobTags]
}),
...
})
我用它来填充
form
.
可以重置为原始值:
this.formGroup.reset({
general: {
description: this.job.description,
country: this.job.country,
nextRun: this.job.nextRun,
lastRun: this.job.lastRun,
enabled: this.job.enabled,
tags: this.jobTags
},
...
})
这是通过另一个事件输出的
Component
EventEmitter
.
我注意到
将其所有值设置为
null
按下按钮,在
reset
方法被调用。这使得整个表单“滞后”,因为值基本上被清除并重新插入到字段中。
这是意料之中的事吗?还是我的错?
<button
mat-stroked-button
type="reset" <!-- Must be removed -->
(click)="restorePressed.emit()"
>
<mat-icon>restore</mat-icon>
Restore
</button>
如你所见,按钮被标记为
type="reset"
. 就这么简单。