<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<div ng-app="myApp" ng-controller="Ctrl">
<div ng-repeat="object in myData">
<div id="obj{{object.id}}">
Hi
<bars-chart></bars-chart>
</div>
</div>
</div>
JavaScript
angular.module('myApp', []).
//camel cased directive name
//in your HTML, this will be named as bars-chart
directive('barsChart', function ($parse) {
//explicitly creating a directive definition variable
//this may look verbose but is good for clarification purposes
//in real life you'd want to simply return the object {...}
var directiveDefinitionObject = {
restrict: 'E',
link: function (scope, element, attrs) {
var obj = scope.object;
//in D3, any selection[0] contains the group
//selection[0][0] is the DOM node
//but we won't need that this time
var test = d3.selectAll("div");
console.log(test);
var chart = d3.select("#obj" +obj.id);
console.log(chart);
}
};
return directiveDefinitionObject;
});
function Ctrl($scope) {
$scope.myData = [ {"id":"1"}, {"id":"2"}];
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.