AngularJS newbie question. I want to write a plotting directive. Let's say I have this:
app.controller("dirCtrl", function($scope) {
$scope.datapoints = [
{ x: 1.169, y: 1.810, label: "Point-0" },
{ x: 1.585, y: 0.508, label: "Point-1" },
{ x: 7.604, y: 2.735, label: "Point-2" },
...
];
});
Then I would like my directive to be like this:
<my-plot xLabel="Some Numbers" xUnits="grams"
yLabel="Some Values" yUnits="mm"
data="datapoints" />
My problem is that "datapoints" does not get bound to $scope.datapoints I've also tried writing the attribute as data="{{datapoints}}" without success either.
My directive definition, in its own module:
angular.module("plotDirectives", [])
.directive("myPlot", function() {
return {
restrict: "E",
scope: true, //'cos I want access to the controller's scope right?
link: function(scope, iElement, iAttrs) {
/* would draw fancy chart if I only could access
the datapoints in the 'data' attribute */
};
});
What am I missing or what would be a better approach for my directive to get to the controller's scope datapoints? Thank you.