Skip to content

Commit 5d1e2e2

Browse files
author
Gonzalo Ruiz de Villa
committed
fix(select): select multiple now uses watchCollection on attr.ngModel
With the fix on watchCollection, this code needed to be updated to run all previous tests on select.
1 parent bf69ca0 commit 5d1e2e2

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/ng/directive/select.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
266266
}
267267

268268
function Multiple(scope, selectElement, ctrl) {
269-
var lastView;
270269
ctrl.$render = function() {
271270
var items = new HashMap(ctrl.$viewValue);
272271
forEach(selectElement.find('option'), function(option) {
273272
option.selected = isDefined(items.get(option.value));
274273
});
275274
};
276275

277-
// we have to do it on each watch since ngModel watches reference, but
278-
// we need to work of an array, so we need to see if anything was inserted/removed
279-
scope.$watch(function selectMultipleWatch() {
280-
if (!equals(lastView, ctrl.$viewValue)) {
281-
lastView = copy(ctrl.$viewValue);
282-
ctrl.$render();
283-
}
276+
scope.$watchCollection(attr.ngModel, function selectMultipleWatch(newValue, oldValue) {
277+
ctrl.$viewValue = newValue;
278+
requiredValidator && requiredValidator(newValue);
279+
ctrl.$render();
284280
});
285281

286282
selectElement.on('change', function() {

0 commit comments

Comments
 (0)