I'm new to angularjs and I have a question about directives. Are they reusable? If so, how can we use them?
Currently, I have a bar chart directive as follows:
directive('bars1', function ($parse) {
return {
restrict: 'E',
scope: {
data: '=',
label: '@'
},
replace: true,
link: function (scope, element, attrs) {
var chart = d3.select('#chart')
.append("div").attr("class", "chart")
.selectAll('div')
.data(scope.data).enter()
.append("div")
.transition().ease("elastic")
.style("width", function(d) { return (d/1000)-10 + "%"; })
.text(function(d) { return d ; });
}
};
})
I want to use the directive in two different divs like this:
<div id="dashboard1" >
<div id="bars" style="margin-top:20%">
<div id="chart">
<bars1 data=val></bars1>
</div>
</div>
</div>
<div id="dashboard2" >
<div id="bars" style="margin-top:20%" >
<div id="chart">
<bars1 data=val></bars1>
</div>
</div>
</div>
However, I am facing an issue where only one chart is created in the first div instead of two separate charts in two different divs. Can anyone help me with this problem?