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

冷暖自知 提交于 2019-12-09 14:54:54

问题


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?


回答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);
  });
}



回答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.



来源:https://stackoverflow.com/questions/32019330/what-is-the-complete-list-of-events-supported-by-angulars-updateon-property-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!