I am currently in the process of developing a directive that requires additional details to be passed as attributes for the elements.
These attributes have static values and do not have any scoped reference in the parent scope (they are boolean values).
However, when trying to access these attributes in the link function of the directive, they appear as undefined.
Example Markup:
<div ng-app="myApp">
<div ng-controller="MainCtrl">
<div my-directive local-attr="attribute" local-ref="ref">
</div>
</div>
</div>
Sample JavaScript:
var myApp = angular.module('myApp', []);
myApp.directive('myDirective', function(){
return {
scope: {
localAttr:'@',
localRef:'='
},
link: function(scope, iElement, iAttrs, controller) {
console.log(scope.localAttr, scope.localRef);
}
};
});
myApp.controller('MainCtrl', ['$scope', function($scope){
$scope.ref="reg"
}]);
In this example, I need to retrieve the value attribute
for scope.localAttr
within the link function.
Check out the Demo here: Fiddle