Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 87a2ff7

Browse files
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.
1 parent 5be6f99 commit 87a2ff7

File tree

5 files changed

+407
-172
lines changed

5 files changed

+407
-172
lines changed

src/AngularPublic.js

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
$jsonpCallbacksProvider,
8080
$LocationProvider,
8181
$LogProvider,
82+
$ModelOptionsProvider,
8283
$ParseProvider,
8384
$RootScopeProvider,
8485
$QProvider,
@@ -246,6 +247,7 @@ function publishExternalAPI(angular) {
246247
$jsonpCallbacks: $jsonpCallbacksProvider,
247248
$location: $LocationProvider,
248249
$log: $LogProvider,
250+
$modelOptions: $ModelOptionsProvider,
249251
$parse: $ParseProvider,
250252
$rootScope: $RootScopeProvider,
251253
$q: $QProvider,

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ function createDateInputType(type, regexp, parseDate, format) {
14241424
return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {
14251425
badInputChecker(scope, element, attr, ctrl);
14261426
baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
1427-
var timezone = ctrl && ctrl.$options && ctrl.$options.timezone;
1427+
var timezone = ctrl && ctrl.$options.getOption('timezone');
14281428
var previousDate;
14291429

14301430
ctrl.$$parserName = type;

0 commit comments

Comments
 (0)