(scope, selectElement, ctrl)
| 25892 | } |
| 25893 | |
| 25894 | function setupAsMultiple(scope, selectElement, ctrl) { |
| 25895 | var lastView; |
| 25896 | ctrl.$render = function() { |
| 25897 | var items = new HashMap(ctrl.$viewValue); |
| 25898 | forEach(selectElement.find('option'), function(option) { |
| 25899 | option.selected = isDefined(items.get(option.value)); |
| 25900 | }); |
| 25901 | }; |
| 25902 | |
| 25903 | // we have to do it on each watch since ngModel watches reference, but |
| 25904 | // we need to work of an array, so we need to see if anything was inserted/removed |
| 25905 | scope.$watch(function selectMultipleWatch() { |
| 25906 | if (!equals(lastView, ctrl.$viewValue)) { |
| 25907 | lastView = shallowCopy(ctrl.$viewValue); |
| 25908 | ctrl.$render(); |
| 25909 | } |
| 25910 | }); |
| 25911 | |
| 25912 | selectElement.on('change', function() { |
| 25913 | scope.$apply(function() { |
| 25914 | var array = []; |
| 25915 | forEach(selectElement.find('option'), function(option) { |
| 25916 | if (option.selected) { |
| 25917 | array.push(option.value); |
| 25918 | } |
| 25919 | }); |
| 25920 | ctrl.$setViewValue(array); |
| 25921 | }); |
| 25922 | }); |
| 25923 | } |
| 25924 | |
| 25925 | function setupAsOptions(scope, selectElement, ctrl) { |
| 25926 | var match; |
no test coverage detected