(scope, selectElement, ctrl)
| 21486 | } |
| 21487 | |
| 21488 | function setupAsMultiple(scope, selectElement, ctrl) { |
| 21489 | var lastView; |
| 21490 | ctrl.$render = function() { |
| 21491 | var items = new HashMap(ctrl.$viewValue); |
| 21492 | forEach(selectElement.find('option'), function(option) { |
| 21493 | option.selected = isDefined(items.get(option.value)); |
| 21494 | }); |
| 21495 | }; |
| 21496 | |
| 21497 | // we have to do it on each watch since ngModel watches reference, but |
| 21498 | // we need to work of an array, so we need to see if anything was inserted/removed |
| 21499 | scope.$watch(function selectMultipleWatch() { |
| 21500 | if (!equals(lastView, ctrl.$viewValue)) { |
| 21501 | lastView = shallowCopy(ctrl.$viewValue); |
| 21502 | ctrl.$render(); |
| 21503 | } |
| 21504 | }); |
| 21505 | |
| 21506 | selectElement.on('change', function() { |
| 21507 | scope.$apply(function() { |
| 21508 | var array = []; |
| 21509 | forEach(selectElement.find('option'), function(option) { |
| 21510 | if (option.selected) { |
| 21511 | array.push(option.value); |
| 21512 | } |
| 21513 | }); |
| 21514 | ctrl.$setViewValue(array); |
| 21515 | }); |
| 21516 | }); |
| 21517 | } |
| 21518 | |
| 21519 | function setupAsOptions(scope, selectElement, ctrl) { |
| 21520 | var match; |
no test coverage detected