MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / setupAsMultiple

Function setupAsMultiple

code/songhop/www/lib/angular/angular.js:25534–25563  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

25532 }
25533
25534 function setupAsMultiple(scope, selectElement, ctrl) {
25535 var lastView;
25536 ctrl.$render = function() {
25537 var items = new HashMap(ctrl.$viewValue);
25538 forEach(selectElement.find('option'), function(option) {
25539 option.selected = isDefined(items.get(option.value));
25540 });
25541 };
25542
25543 // we have to do it on each watch since ngModel watches reference, but
25544 // we need to work of an array, so we need to see if anything was inserted/removed
25545 scope.$watch(function selectMultipleWatch() {
25546 if (!equals(lastView, ctrl.$viewValue)) {
25547 lastView = shallowCopy(ctrl.$viewValue);
25548 ctrl.$render();
25549 }
25550 });
25551
25552 selectElement.on('change', function() {
25553 scope.$apply(function() {
25554 var array = [];
25555 forEach(selectElement.find('option'), function(option) {
25556 if (option.selected) {
25557 array.push(option.value);
25558 }
25559 });
25560 ctrl.$setViewValue(array);
25561 });
25562 });
25563 }
25564
25565 function setupAsOptions(scope, selectElement, ctrl) {
25566 var match;

Callers 1

angular.jsFile · 0.70

Calls 5

getMethod · 0.80
forEachFunction · 0.70
isDefinedFunction · 0.70
equalsFunction · 0.70
shallowCopyFunction · 0.70

Tested by

no test coverage detected