| 14521 | } |
| 14522 | |
| 14523 | function Multiple(scope, selectElement, ctrl) { |
| 14524 | var lastView; |
| 14525 | ctrl.$render = function() { |
| 14526 | var items = new HashMap(ctrl.$viewValue); |
| 14527 | forEach(selectElement.find('option'), function(option) { |
| 14528 | option.selected = isDefined(items.get(option.value)); |
| 14529 | }); |
| 14530 | }; |
| 14531 | |
| 14532 | // we have to do it on each watch since ngModel watches reference, but |
| 14533 | // we need to work of an array, so we need to see if anything was inserted/removed |
| 14534 | scope.$watch(function selectMultipleWatch() { |
| 14535 | if (!equals(lastView, ctrl.$viewValue)) { |
| 14536 | lastView = copy(ctrl.$viewValue); |
| 14537 | ctrl.$render(); |
| 14538 | } |
| 14539 | }); |
| 14540 | |
| 14541 | selectElement.bind('change', function() { |
| 14542 | scope.$apply(function() { |
| 14543 | var array = []; |
| 14544 | forEach(selectElement.find('option'), function(option) { |
| 14545 | if (option.selected) { |
| 14546 | array.push(option.value); |
| 14547 | } |
| 14548 | }); |
| 14549 | ctrl.$setViewValue(array); |
| 14550 | }); |
| 14551 | }); |
| 14552 | } |
| 14553 | |
| 14554 | function Options(scope, selectElement, ctrl) { |
| 14555 | var match; |