Is there an equivalent to this in angular 2?
ng-model-options=\"{ updateOn: \'blur\' }\"
Thanks
In Angular 2 you can use the native DOM events
<input (blur)="someMethod()" />
Now, just define a method that does what you need when the field is blurred
Even though this is a very old thread, there is now a very neat solution which comes with Angular5.
You trigger the update on blur like this:
Tempalte driven forms:
<input [(ngModel)]="lastname" [ngModelOptions]="{ updateOn: 'blur' }">
Reactive forms:
this.nameForm = new FormGroup ({
firstname: new FormControl('', {
validators: Validators.required,
updateOn: 'submit'
}),
lastname: new FormControl('', {
validators: Validators.required,
updateOn: 'submit'
})
});
(you can select submit
or blur
as values)
Reference: https://medium.com/codingthesmartway-com-blog/angular-5-forms-update-9587c3735cd3