I'm trying to access attr data defined by a controller in a custom directive's link function.
Here is some simple angular markup:
<div class='barChart'>
{{vm.totals}}
<bar-chart chart-data='vm.totals'></bar-chart
</div>
This is the directive defintion:
angular
.module('app')
.directive('barChart', [Callback])
function Callback() {
return {
restrict: 'E',
replace: false,
scope: {data: '=chartData'},
link: (scope, el, attrs) => {
console.log(scope);
console.log(el);
console.log(attrs.chartData);
}
}
}
When I log scope, I can see the data array in this object as expected, heres a picture:
As you can see the data is the 10 item array at the bottom. The array also shows up in the browser, so the data is there. However, as soon as I change the console.log
to log that property:
console.log(scope.data)
The value that gets printed is undefined. I'm trying to access the data in the link function so that I can use d3 to create a visualization. The data is there, but it's undefined as soon as I call .data
on scope. Any ideas?