如何使角度2的模糊更新表单模型

mat*_*iel 15 angular2-forms angular

在角度2中是否有相当于这个?

ng-model-options="{ updateOn: 'blur' }"
Run Code Online (Sandbox Code Playgroud)

谢谢

TGH*_*TGH 20

在Angular 2中,您可以使用本机DOM事件

<input (blur)="someMethod()" />
Run Code Online (Sandbox Code Playgroud)

现在,只需定义一个方法,在字段模糊时执行所需的操作


dav*_*688 9

即使这是一个非常古老的线程,现在有一个非常简洁的解决方案,它与Angular5一起提供.

您可以触发模糊更新,如下所示:

Tempalte驱动形式:

<input [(ngModel)]="lastname" [ngModelOptions]="{ updateOn: 'blur' }">
Run Code Online (Sandbox Code Playgroud)

反应形式:

this.nameForm = new FormGroup ({
  firstname: new FormControl('', {
    validators: Validators.required,
    updateOn: 'submit'
  }),
  lastname: new FormControl('', {
    validators: Validators.required,
    updateOn: 'submit'
  })
});
Run Code Online (Sandbox Code Playgroud)

(您可以选择submitblur作为值)

参考:https: //medium.com/codingthesmartway-com-blog/angular-5-forms-update-9587c3735cd3