2017-05-15 66 views
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> 

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

+0

尝试'

回答

0

这工作:$ event.preventDefault()

感谢您的链接,Achraf JEDAY!