Angular 2 ngSubmit.emit()不会更改<myform> .form.submitted属性

时间:2017-09-19 11:57:02

标签: angular

我的以下代码触发addResult()方法属性,但提交的属性始终为空。任何猜测?

<form class="form-horizontal" (ngSubmit)="addResult()" #resultForm="ngForm">
    <p>is form submitted? {{resultForm.form.submitted}}</p>
    ...
    <button type="submit" (click)="resultForm.ngSubmit.emit()" class="btn btn-primary" data-dismiss="modal" id="saveDialog">Sauvegarder</button>
</form>

1 个答案:

答案 0 :(得分:0)

更改为

  1. 将某些内容传递给该函数。
  2. 删除resultForm.ngSubmit.emit(),这是不必要的。
  3. 它只是resultForm.submitted
  4. 创建了Plunker

     <form class="form-horizontal" (ngSubmit)="addResult(resultForm)" #resultForm="ngForm">
     <p>is form submitted? {{resultForm.submitted}}</p>
    
    ...
    <button type="submit" class="btn btn-primary" data-dismiss="modal" id="saveDialog">Sauvegarder</button>