I am creating a directive that process data from attribute value. the directive is only going to be used as an attribute on an element. So for now i just want to run a function whenever it is called
The directive call is like this:
<div rest="accounts">
{{testing}}
</div>
Directive definition goes like this:
app.directive("rest", [function(){
return {
restrict: 'A',
scope: {
rest: '='
},
link: function(scope, element, attrs, ctrl) {
console.log(scope);
}
};
}])
everytime i use the directive, the log shows the property rest as undefined.. accounts is just a string because i want to test the directive first, but yet i don't know why it is always undefined, even with using $watch like this:
app.directive("rest", [function(){
return {
restrict: 'A',
scope: {
rest: '='
},
link: function(scope, element, attrs, ctrl) {
scope.$watch('rest', function(data){
console.log(data); //Still undefined
});
}
};
}])
accountmust be undefined before giving it to the directive. How is it initialized?accountsis just a string. it is not attached to any scope