You can explain the ngList directive

I have code for the ngList directive developed by AngularJS. I would like to implement something similar to it, but I do not understand parts of the code. Here is the code

var ngListDirective = function() {
  return {
    require: 'ngModel',
    link: function(scope, element, attr, ctrl) {
      var match = /\/(.*)\//.exec(attr.ngList),
          separator = match && new RegExp(match[1]) || attr.ngList || ',';

      var parse = function(viewValue) {
        var list = [];

        if (viewValue) {
          forEach(viewValue.split(separator), function(value) {
            if (value) list.push(trim(value));
          });
        }

        return list;
      };

      ctrl.$parsers.push(parse);
      ctrl.$formatters.push(function(value) {
        if (isArray(value)) {
          return value.join(', ');
        }

        return undefined;
      });
    }
  };
};

Here are the parts that I do not understand:

  • function (scope, element, attr, ctrl) : ctrl variable. Where can I find out more about this.
  • ctrl. $ parsers.push (parse); : where can I find out more about this use
  • ctrl. $ formatters.push (function (value) { : I need to understand this as I will try to implement something like this
  • required: 'ngModel' : why ngModel required
+4
source share
1 answer

-, !

ctrl - (s) ( , ngModel, require:)

$parsers $formatters- http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController

, Angular DOM ngModel, Angular, $parsers DOM- ngModel Angular . $formatters DOM. , , $parsers DOM , $formatters .

, ngModel. ngList ngModel. ngModel, ngList ( ctrl)

+5

All Articles