Is there a way to pass the configuration object into a custom directive that is defined as an attribute directive?
I have an object in the controller that I want to send to the directive:
$scope.configObject = {
count: 5,
mode: 'fast',
getData: myService.getData // function of external service that avaliable in controller
}
In my view, I declare a directive:
<div class='list-class' my-list='configObject'></div>
The directive is as follows:
return {
restrict: 'A',
link: function(scope, elem, attrs) {
var config = angular.fromJson(attrs.myList);
}
}
I tried to get the configuration object using angular.getJson - but it does not work for functions (it is possible to get only the score and mode). Is .getJson () the wrong way to get the configuration?
Also (I think this is not even possible) - is there a way to get the configuration object, avoiding access to
attrs.myList
directly? I mean, if I change the directive initialization from
.directive('myList', function() { ... }) to
.directive('myCustomList', function() { ... })
I have to change access to
attrs.myCustomList
because the view will look like
<div class='list-class' my-custom-list='configObject'></div>