(scope, selectElement, ctrl)
| 21776 | } |
| 21777 | |
| 21778 | function setupAsMultiple(scope, selectElement, ctrl) { |
| 21779 | var lastView; |
| 21780 | ctrl.$render = function() { |
| 21781 | var items = new HashMap(ctrl.$viewValue); |
| 21782 | forEach(selectElement.find('option'), function(option) { |
| 21783 | option.selected = isDefined(items.get(option.value)); |
| 21784 | }); |
| 21785 | }; |
| 21786 | |
| 21787 | // we have to do it on each watch since ngModel watches reference, but |
| 21788 | // we need to work of an array, so we need to see if anything was inserted/removed |
| 21789 | scope.$watch(function selectMultipleWatch() { |
| 21790 | if (!equals(lastView, ctrl.$viewValue)) { |
| 21791 | lastView = shallowCopy(ctrl.$viewValue); |
| 21792 | ctrl.$render(); |
| 21793 | } |
| 21794 | }); |
| 21795 | |
| 21796 | selectElement.on('change', function() { |
| 21797 | scope.$apply(function() { |
| 21798 | var array = []; |
| 21799 | forEach(selectElement.find('option'), function(option) { |
| 21800 | if (option.selected) { |
| 21801 | array.push(option.value); |
| 21802 | } |
| 21803 | }); |
| 21804 | ctrl.$setViewValue(array); |
| 21805 | }); |
| 21806 | }); |
| 21807 | } |
| 21808 | |
| 21809 | function setupAsOptions(scope, selectElement, ctrl) { |
| 21810 | var match; |
no test coverage detected