-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngModelController): allow $overrideModelOptions to set updateOn #16352
Conversation
559f92d
to
3984ce4
Compare
I think, due to inheritance, that implementing this is more complicated than it seems. If a child ngModel is inheriting the current ngModelOptions, then changing the |
I've added a note that overrideModelOptions does not propagate the changes. This is a general problem - even the simple options like debounce, allowInvalid are not updated. |
src/ng/directive/ngModel.js
Outdated
* <div class="alert alert-warning"> | ||
* **Note:** overriding the model options with this function only affects the | ||
* current `ngModelController` and does not propagate the new options to | ||
* `ngModelOptions` directives that have initially inherited from it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, since createChild()
returns a new instance, nobody has inherited from it. It might make sense to highlight that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the whole notice is irrelevant, as you can only $overrideModelOptions on ngModel, and nested ngModels are definitely "here be dragons" territory. Or should we mention that this doesn't change the options on ngModelOptions that this instance has inherited from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think you are right. The inheritance is between ngModelOptions
(which can be nested). ngModel
just takes the options of its nearest ngModuleOptions
and it can overwrite them. Where the corresponding ngModelOptions
got its values (inherited or not) is not affected (nor is there any reason to assume it would).
src/ng/directive/ngModel.js
Outdated
@@ -1321,9 +1348,7 @@ var ngModelDirective = ['$rootScope', function($rootScope) { | |||
post: function ngModelPostLink(scope, element, attr, ctrls) { | |||
var modelCtrl = ctrls[0]; | |||
if (modelCtrl.$options.getOption('updateOn')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check could be skipped here.
src/ng/directive/ngModel.js
Outdated
} | ||
|
||
this.$$updateEvents = this.$options.getOption('updateOn'); | ||
this.$$element.on(this.$$updateEvents, this.$$updateEventHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to avoid this call if $$updateEvents
are empty. (Several operations take place unnecessarily.)
* matches the default events belonging to the control. These are the events that are bound to | ||
* the control, and when fired, update the `$viewValue` via `$setViewValue`. | ||
* | ||
* `ngModelOptions` considers every event that is not listed in `updateOn` a "default" event, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😞
src/ng/directive/ngModelOptions.js
Outdated
* ### Default events, extra triggers, and catch-all debounce values | ||
* | ||
* This example shows the relationship between "default" update events and | ||
* additional `updateOn`triggers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing whitespace before triggers
.
src/ng/directive/ngModelOptions.js
Outdated
}); | ||
* </file> | ||
* <file name="template.html"> | ||
<form name="$ctrl.form"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too little indentation.
src/ng/directive/ngModelOptions.js
Outdated
<form name="$ctrl.form"> | ||
Input: <input type="text" name="input" ng-model="$ctrl.name" ng-model-options="$ctrl.options" /> | ||
</form> | ||
Model: <tt>{{$ctrl.name}}</tt> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much indentation.
src/ng/directive/ngModelOptions.js
Outdated
<input type="submit" value="Update options"> | ||
</form> | ||
* </file> | ||
* </example> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one advanced example indeed. I am not even sure what it does 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you read the description? 😛
3984ce4
to
baac542
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - despite @gkalpak's sad face.
The extra explanatory docs are great.
src/ng/directive/ngModelOptions.js
Outdated
}; | ||
|
||
this.updateEvents = function() { | ||
var eventL = this.options.updateOn.split(' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventL?
Also adds more docs about "default" events and how to override ModelOptions. Closes angular#16351
baac542
to
7f59fa1
Compare
Also adds more docs about "default" events and how to override ngModelController options. Closes angular#16351 Closes angular#16352
Also adds more docs about "default" events and how to override
ModelOptions.
Closes #16351
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change?
Please check if the PR fulfills these requirements
Other information: