aboutsummaryrefslogtreecommitdiffstats
path: root/src/directive
diff options
context:
space:
mode:
authorMisko Hevery2012-03-15 14:19:20 -0700
committerMisko Hevery2012-03-19 11:35:10 -0700
commit6ecac8e71a84792a434d21db2c245b3648c55f18 (patch)
treeeb10745ed4de06762e1dccad8c1c8d141b72277e /src/directive
parent823adb231995e917bc060bfa49453e2a96bac2b6 (diff)
downloadangular.js-6ecac8e71a84792a434d21db2c245b3648c55f18.tar.bz2
fix(select): multiselect failes to update view on selection insert
In multiselect when the underlying selection array push/pops an element the view did not re-render since the array reference stayed the same.
Diffstat (limited to 'src/directive')
-rw-r--r--src/directive/select.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/directive/select.js b/src/directive/select.js
index 9ea0186d..b70339fc 100644
--- a/src/directive/select.js
+++ b/src/directive/select.js
@@ -174,6 +174,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
}
function Multiple(scope, selectElement, ctrl) {
+ var lastView;
ctrl.$render = function() {
var items = new HashMap(ctrl.$viewValue);
forEach(selectElement.children(), function(option) {
@@ -181,6 +182,15 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
});
};
+ // we have to do it on each watch since ng-model watches reference, but
+ // we need to work of an array, so we need to see if anything was inserted/removed
+ scope.$watch(function() {
+ if (!equals(lastView, ctrl.$viewValue)) {
+ lastView = copy(ctrl.$viewValue);
+ ctrl.$render();
+ }
+ });
+
selectElement.bind('change', function() {
scope.$apply(function() {
var array = [];