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

Function setupAsMultiple

test/angular/1.2/angular.js:21778–21807  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

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;

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