12

I've found nice feature in angularjs. Directives can be set to work on comments.

{
    ...
    restrict: 'M'
    ...
}

This does the trick as it is spoken in the documentation. Usage of this directive is as follows:

<!-- directive: my-directive-name -->

And it works just fine as long as I don't need to pass arguments to this directive. Is it possible to set arguments on directive restricted to comment? What's the syntax?

Szymon Wygnański
  • 10,642
  • 6
  • 31
  • 44

1 Answers1

19
<!-- directive: my-directive-name this is all an argument -->

Where everything after the directive name is the value passed into the directive.

app.directive('myDirectiveName', function(){
   return {
      restrict: 'M',
      link: function(scope, elem, attr) {
          alert(attr.myDirectiveName); //alerts "this is all an argument"
      }
   };
});
Ben Lesh
  • 107,825
  • 47
  • 247
  • 232