MCPcopy
hub / github.com/angular-ui/ui-grid / ngListDirective

Function ngListDirective

lib/test/angular/1.6.7/angular.js:28484–28524  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28482 *
28483 */
28484var ngListDirective = function() {
28485 return {
28486 restrict: 'A',
28487 priority: 100,
28488 require: 'ngModel',
28489 link: function(scope, element, attr, ctrl) {
28490 var ngList = attr.ngList || ', ';
28491 var trimValues = attr.ngTrim !== 'false';
28492 var separator = trimValues ? trim(ngList) : ngList;
28493
28494 var parse = function(viewValue) {
28495 // If the viewValue is invalid (say required but empty) it will be `undefined`
28496 if (isUndefined(viewValue)) return;
28497
28498 var list = [];
28499
28500 if (viewValue) {
28501 forEach(viewValue.split(separator), function(value) {
28502 if (value) list.push(trimValues ? trim(value) : value);
28503 });
28504 }
28505
28506 return list;
28507 };
28508
28509 ctrl.$parsers.push(parse);
28510 ctrl.$formatters.push(function(value) {
28511 if (isArray(value)) {
28512 return value.join(ngList);
28513 }
28514
28515 return undefined;
28516 });
28517
28518 // Override the standard $isEmpty because an empty array means the input is empty.
28519 ctrl.$isEmpty = function(value) {
28520 return !value || !value.length;
28521 };
28522 }
28523 };
28524};
28525
28526/* global VALID_CLASS: true,
28527 INVALID_CLASS: true,

Callers

nothing calls this directly

Calls 2

trimFunction · 0.70
isArrayFunction · 0.50

Tested by

no test coverage detected