I have an angular directive that is a custom attribute that possibly can contain a value like so:
<div my-directive="myVal"></div>
How do I read myVal (as a string) from inside my directive's link function?
The passed value is on the attributes object passed as the third argument to the link function. It's under a property matching the name of the directive.
app.directive('myDirective', function() {
   return {
       restrict: 'A',
       link: function(scope, elem, attr) {
            //read the passed value
            alert(attr.myDirective);
       }
   }
});
                        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