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?
Restrict. Angular allows us to set a property named restrict on the object we return on our directive definition. We can pass through a string with certain letters letting Angular know how our directive can be used. function MyDirective() { return { restrict: 'E', template: '<div>Hello world!
Directive comes with many Directive Definition Objects (DDO). From them restrict is one. Using restrict option inside a Custom Directive we can prevent the access level of Directive for Element(E), Attribute(A), Comment(M) or Class(C).
Note: When you create a directive, it is restricted to attribute and elements only by default. In order to create directives that are triggered by class name, you need to use the restrict option. The restrict option is typically set to: 'A' - only matches attribute name.
<!-- 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"
}
};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With