MCPcopy Create free account
hub / github.com/angular-ui/ui-router / ngListDirective

Function ngListDirective

test/angular/1.5/angular.js:27600–27642  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27598 * @param {string=} ngList optional delimiter that should be used to split the value.
27599 */
27600var ngListDirective = function() {
27601 return {
27602 restrict: 'A',
27603 priority: 100,
27604 require: 'ngModel',
27605 link: function(scope, element, attr, ctrl) {
27606 // We want to control whitespace trimming so we use this convoluted approach
27607 // to access the ngList attribute, which doesn't pre-trim the attribute
27608 var ngList = element.attr(attr.$attr.ngList) || ', ';
27609 var trimValues = attr.ngTrim !== 'false';
27610 var separator = trimValues ? trim(ngList) : ngList;
27611
27612 var parse = function(viewValue) {
27613 // If the viewValue is invalid (say required but empty) it will be `undefined`
27614 if (isUndefined(viewValue)) return;
27615
27616 var list = [];
27617
27618 if (viewValue) {
27619 forEach(viewValue.split(separator), function(value) {
27620 if (value) list.push(trimValues ? trim(value) : value);
27621 });
27622 }
27623
27624 return list;
27625 };
27626
27627 ctrl.$parsers.push(parse);
27628 ctrl.$formatters.push(function(value) {
27629 if (isArray(value)) {
27630 return value.join(ngList);
27631 }
27632
27633 return undefined;
27634 });
27635
27636 // Override the standard $isEmpty because an empty array means the input is empty.
27637 ctrl.$isEmpty = function(value) {
27638 return !value || !value.length;
27639 };
27640 }
27641 };
27642};
27643
27644/* global VALID_CLASS: true,
27645 INVALID_CLASS: true,

Callers

nothing calls this directly

Calls 2

isArrayFunction · 0.85
trimFunction · 0.70

Tested by

no test coverage detected