What is the complete list of events supported by angular's updateOn property of ngModelOptions?

All we need is an easy explanation of the problem, so here it is.

The docs say

updateOn: string specifying which event should the input be bound to. You can set several events using an space delimited list. There is a special event called default that matches the default events belonging of the control.

The page mentions a few events: blur, default, submit. Are there any others? Is the full list documented anywhere?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

As far as i know, you can bind any available DOM event to the updateOn property. see a full list here.

Having a look at the Source of ngModel, you can see that the options passed to updateOn will get bound to the actual element itself.

https://github.com/angular/angular.js/blob/master/src/ng/directive/ngModel.js#L1188

Angular Source:

if (modelCtrl.$options.getOption('updateOn')) {
  element.on(modelCtrl.$options.getOption('updateOn'), function(ev) {
    modelCtrl.$$debounceViewValueCommit(ev && ev.type);
  });
}

Method 2

You can now control for a form (or single form elements) when the
value or the validity is updated. This feature has been available in
AngularJS 1.x but missed in Angular 2+ so far. The following update
options can now be used in Angular 5 forms:

change: change is the default mode. By using this update option the form / form control is updated after every single change.

blur: the blur change mode is only updated the from values / validity status after a form control lost the focus.

submit: updates are only done after form submit.

Full source is here.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply