How to get the value of an attribute in a template in an angularjs custom directive?
I'm trying to get the "abc" attributes defined as a custom directive in angularjs:
<div abc="user">
Access granted!
</div>
and then change the text inside the div with a special directive:
.directive('abc', function() {
var attr;
return {
link: function (scope, element, attributes) {
attr = attributes.abc;
console.log(attr);
},
template: "" + attr
};
});
The result should be "user", but undefined because attr was not set when the template was executed. So, any possible help for solving this problem?
+3
source to share
3 answers