【问题标题】:Toast message with reset带有重置的 Toast 消息
【发布时间】: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>

当我点击重置时,表单被重置,并显示“已保存”。信息。我究竟做错了什么?

【问题讨论】:

标签: angular submit toast reactive


【解决方案1】:

这有效:$event.preventDefault()

感谢该链接,Achraf JEDAY!

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多