Is there an equivalent to this in angular 2?
ng-model-options="{ updateOn: 'blur' }"
Thanks
Post Editor. When using Angular Forms, by default, on every keystroke, the values of your form controls are updated and their associated validators are executed.
The PatchValue is used to update only a subset of the elements of the FormGroup or FormArray . It will only update the matching objects and ignores the rest.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With