【发布时间】:2017-10-14 11:53:48
【问题描述】:
我有一个带有提交按钮和重置按钮的响应式表单。两者都按预期工作,但重置功能显示从提交触发的 Toast 消息。
onSubmit() {
this.service.update(data, this.id)
.subscribe(response => {
this.getDetails();
this.toaster.showToaster('Saved.');
});
}
resetForm(){
this.setFormValues();
}
setFormValues() {
this.form.setValue({
name: this.plan.name,
account: this.plan.account
});
}
getDetails() {
this.service.getById(this.id)
.subscribe(rem => {
this.plan = rem;
this.setFormValues();
});
}
HTML:
<form [formGroup]="form" (ngSubmit)="onSubmit();" novalidate>
<table class="detailTable">
<tr>
<td>name:</td>
<td>{{name}}</td>
</tr> ...
</table>
<div class="button-row">
<button type="submit" [disabled]="form.pristine" md-raised-button>Save</button>
<button (click)="resetForm()" [disabled]="form.pristine" md-raised-button>Reset</button>
</div>
<span>
</span>
</form>
当我点击重置时,表单被重置,并显示“已保存”。信息。我究竟做错了什么?
【问题讨论】:
-
试试
<button type="button"...另见stackoverflow.com/questions/38786995/…
标签: angular submit toast reactive