重置的Toast消息

时间:2017-05-15 15:51:27

标签: angular submit toast reactive

我有一个带有提交按钮和重置按钮的被动表单。两者都按预期工作,但重置功能显示从提交触发的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>

当我点击重置时,表单会重置,并显示&#34;已保存。&#34;信息。我究竟做错了什么?

1 个答案:

答案 0 :(得分:0)

这有效:$ event.preventDefault()

感谢您的链接,Achraf JEDAY!