SIGN IN SIGN UP
angular / angular.js UNCLAIMED

AngularJS - HTML enhanced for web apps!

0 0 0 JavaScript

feat(ngModelOptions): allow options to be inherited from ancestor ngModelOptions

Previously, you had to apply the complete set of ngModelOptions at every point where
you might want to modify just one or two settings.

This change allows more general settings to be applied nearer to the top of the DOM
and then for more specific settings to override those general settings further down
in the DOM.

Furher there is now a new service `$modelOptions` that acts as the top level options
that are inherited by all ngModelOptions directives that do not already have an
ngModelOptions ancestor directive.

Closes #10922

BREAKING CHANGE:

Previously, if a setting was not applied on ngModelOptions, then it would default
to undefined. Now the setting will be inherited from the nearest ngModelOptions
ancestor.

It is possible that an ngModelOptions directive that does not set a property,
has an ancestor ngModelOptions that does set this property to a value other than
undefined. This would cause the ngModel and input controls below this ngModelOptions
directive to display different behaviour. This is fixed by explictly setting the
property in the ngModelOptions to prevent it from inheriting from the ancestor.

For example if you had the following HTML:

```
<form ng-model-options="{updateOn: 'blur'}">
  <input ng-model="...">
</form>
```

Then before this change the input would update on the default event not blur.
After this change the input will inherit the option to update on blur.
If you want the original behaviour then you will need to specify the option
on the input as well:

```
<form ng-model-options="{updateOn: 'blur'}">
  <input ng-model="..." ng-model-options="{updateOn: 'default'}">
</form>
```

The programmatic API for `ngModelOptions` has changed. You must now read options
via the `getOption` method, rather than accessing the option directly as a property
of the options object. This does not affect the usage in templates and only
affects custom directives that might have been reading options for their own purposes.
P
Peter Bacon Darwin committed
87a2ff76af5d0a9268d8eb84db5755077d27c84c
Parent: 5be6f99