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

multiple ng-model-options are not merged when inherited #15201

Closed
AdamSelene opened this issue Sep 30, 2016 · 2 comments
Closed

multiple ng-model-options are not merged when inherited #15201

AdamSelene opened this issue Sep 30, 2016 · 2 comments

Comments

@AdamSelene
Copy link

Since #7212, the example in the documentation indicates that multiple ngModelOptions are merged:

<div ng-model-options="{ allowInvalid: true }">
  <form ng-model-options="{ updateOn: 'blur' }">
    <input ng-model-options="{ updateOn: 'default' }" />
  </form>
</div>

According to the doc, this should yield for the input element:
{ allowInvalid: true, updateOn: 'default' }

But this is not working: options set on children elements will simply override the options from the parent (without merging).
So the input element in the previous exemple has the following options:
{ updateOn: 'default' }

See plunker (I had to inspect the input's ngModel controller to have a look at its $options to be sure)

The documentation (not the example) does not say anything about merging multiple options:

If a setting is not specified as a property on the object for a particular ngModelOptions directive then it will inherit that setting from the first ngModelOptions directive found by traversing up the DOM tree. If there is no ancestor element containing an ngModelOptions directive then the settings in $modelOptions will be used.

So I think the behavior is the expected one, but the example is wrong so this should be a simple doc fix. Is that correct?

@gkalpak
Copy link
Member

gkalpak commented Sep 30, 2016

You are apparently using Angular v1.5.8, but the docs you mention are from the latest code on the master branch. The v1.5.8 docs can be found here and they should be consistent with the behavior in the example.

Note, that there has been a change wrt ngModelOptions. In v1.5.x, an element would inherit its ancestor's ngModelOptions only if it didn't have its own ngModeOptions. Since v1.6.x (yet to be released), the inheritance is more granular, so even if an element has its own ngModelOptions, it will still inherit specific properties that it doesn't have.
(The related PR is #10922.)

(Since this is a breaking change, it will not be backported to v1.5.x, so v1.5.x will keep the current "inherit-all-or-nothing" behavior.)

@AdamSelene
Copy link
Author

My bad, I thought the current docs still applied to 1.5.8 (since latest is still 1.5.9.x) and forgot to check.
Thanks for the clarification!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants