MCPcopy Index your code
hub / github.com/angular-ui/ui-router / setupAsMultiple

Function setupAsMultiple

test/angular/1.3/angular.js:25894–25923  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

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;

Callers 1

angular.jsFile · 0.70

Calls 4

forEachFunction · 0.70
isDefinedFunction · 0.70
equalsFunction · 0.70
shallowCopyFunction · 0.70

Tested by

no test coverage detected