MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / setupAsMultiple

Function setupAsMultiple

test/fixtures/foo.js:21553–21582  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

21551 }
21552
21553 function setupAsMultiple(scope, selectElement, ctrl) {
21554 var lastView;
21555 ctrl.$render = function() {
21556 var items = new HashMap(ctrl.$viewValue);
21557 forEach(selectElement.find('option'), function(option) {
21558 option.selected = isDefined(items.get(option.value));
21559 });
21560 };
21561
21562 // we have to do it on each watch since ngModel watches reference, but
21563 // we need to work of an array, so we need to see if anything was inserted/removed
21564 scope.$watch(function selectMultipleWatch() {
21565 if (!equals(lastView, ctrl.$viewValue)) {
21566 lastView = shallowCopy(ctrl.$viewValue);
21567 ctrl.$render();
21568 }
21569 });
21570
21571 selectElement.on('change', function() {
21572 scope.$apply(function() {
21573 var array = [];
21574 forEach(selectElement.find('option'), function(option) {
21575 if (option.selected) {
21576 array.push(option.value);
21577 }
21578 });
21579 ctrl.$setViewValue(array);
21580 });
21581 });
21582 }
21583
21584 function setupAsOptions(scope, selectElement, ctrl) {
21585 var match;

Callers 1

foo.jsFile · 0.85

Calls 4

forEachFunction · 0.85
isDefinedFunction · 0.85
equalsFunction · 0.85
shallowCopyFunction · 0.85

Tested by

no test coverage detected