我为directive
图表创建了d3js
:
html:
<donuts-chart chart-data="mydonuts" ></donuts-chart>
directive:
.directive('donutsChart', function ($parse) {
var donutobject = {
restrict: 'E',
replace: false,
scope: {data: '=chartData'},
link: function (scope, element, attrs) {
scope.$watch('data', function(newVals, oldVals) {
console.log('there is new data');
}, true);
};
return donutobject;
})
我添加scope.$watch
只是为了测试数据是否正在更新。但它没有用。我怎样才能让它发挥作用?每当有新数据时我都需要更新图表。