MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / ngListDirective

Function ngListDirective

lib/test/angular/1.4.3/angular.js:24291–24333  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24289 * @param {string=} ngList optional delimiter that should be used to split the value.
24290 */
24291var ngListDirective = function() {
24292 return {
24293 restrict: 'A',
24294 priority: 100,
24295 require: 'ngModel',
24296 link: function(scope, element, attr, ctrl) {
24297 // We want to control whitespace trimming so we use this convoluted approach
24298 // to access the ngList attribute, which doesn't pre-trim the attribute
24299 var ngList = element.attr(attr.$attr.ngList) || ', ';
24300 var trimValues = attr.ngTrim !== 'false';
24301 var separator = trimValues ? trim(ngList) : ngList;
24302
24303 var parse = function(viewValue) {
24304 // If the viewValue is invalid (say required but empty) it will be `undefined`
24305 if (isUndefined(viewValue)) return;
24306
24307 var list = [];
24308
24309 if (viewValue) {
24310 forEach(viewValue.split(separator), function(value) {
24311 if (value) list.push(trimValues ? trim(value) : value);
24312 });
24313 }
24314
24315 return list;
24316 };
24317
24318 ctrl.$parsers.push(parse);
24319 ctrl.$formatters.push(function(value) {
24320 if (isArray(value)) {
24321 return value.join(ngList);
24322 }
24323
24324 return undefined;
24325 });
24326
24327 // Override the standard $isEmpty because an empty array means the input is empty.
24328 ctrl.$isEmpty = function(value) {
24329 return !value || !value.length;
24330 };
24331 }
24332 };
24333};
24334
24335/* global VALID_CLASS: true,
24336 INVALID_CLASS: true,

Callers

nothing calls this directly

Calls 2

trimFunction · 0.70
isArrayFunction · 0.50

Tested by

no test coverage detected