Handle re-assignment of dropdown items #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, first of all very nice directive, i've used it in my project and love how it works.
would you consider this pull request based in the following issue?
I found that when the object binded to the dropdown items is re-assigned, the dropdown items are not updated.
for example, if we set the dropdown items in the controller, and then that value is re-assigned later in the app, for example
See it in these plunkers (which i forked from yours, so they will look familiar :p ), I am re-assigning the items in line 100
I believe this is because once it is assigned, the binding in the directive is made to that object (called
scope.defaultDropdownItems
in the directive), and then the variablescope.dropdownItems
is set to the value ofscope.defaultDropdownItems
. But then, if the list is re-assigned,scope.defaultDropdownItems
, will change, but notscope.dropdownItems
because the directive is only making the assignment once at the beginning, and is only "watching" forscope.dropdownItems
.I have worked around this by adding a
$watch
to the directive code, to watch for changes in the variablescope.defaultDropdownItems
, and re-assign the value ofscope.dropdownItems
whenscope.defaultDropdownItems
changes.Additionally I've separated the controller function because in my app i had to
$inject
the dependencies explicitly, but this is not really important.Thanks