0
我有一個反應型表單,具有提交按鈕和重置按鈕。兩者都按預期工作,但重置功能顯示由提交觸發的Toast消息。重置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>
當我點擊復位,表單被重置,並顯示 「保存」。信息。我究竟做錯了什麼?
嘗試'