mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-10 07:44:43 +00:00
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.
This commit is contained in:
parent
823adb2319
commit
6ecac8e71a
2 changed files with 19 additions and 1 deletions
|
|
@ -174,6 +174,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Multiple(scope, selectElement, ctrl) {
|
function Multiple(scope, selectElement, ctrl) {
|
||||||
|
var lastView;
|
||||||
ctrl.$render = function() {
|
ctrl.$render = function() {
|
||||||
var items = new HashMap(ctrl.$viewValue);
|
var items = new HashMap(ctrl.$viewValue);
|
||||||
forEach(selectElement.children(), function(option) {
|
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() {
|
selectElement.bind('change', function() {
|
||||||
scope.$apply(function() {
|
scope.$apply(function() {
|
||||||
var array = [];
|
var array = [];
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,15 @@ describe('select', function() {
|
||||||
scope.selection = ['A'];
|
scope.selection = ['A'];
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(element[0].childNodes[0].selected).toEqual(true);
|
expect(element.find('option')[0].selected).toEqual(true);
|
||||||
|
expect(element.find('option')[1].selected).toEqual(false);
|
||||||
|
|
||||||
|
scope.$apply(function() {
|
||||||
|
scope.selection.push('B');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(element.find('option')[0].selected).toEqual(true);
|
||||||
|
expect(element.find('option')[1].selected).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue