javascript - ng-repeat not updating after change in nestled data -
javascript - ng-repeat not updating after change in nestled data -
i have directive draws using d3.js , if draw depends on info in scope. problem can't redraw things after change, i've tried variants $scope.$apply , haven't had success far.
html:
<body ng-app="app" ng-controller="mainctrl"> <div ng-repeat="val in data"> <div draw="" value="{{val.avg}}">{{val.avg}}</div> </div> </body>
js:
var app = angular.module('app', []); app.controller('mainctrl', function ($scope, $timeout) { $scope.data = [{avg: 0}, {avg: 1}]; $timeout(function (){ var = 1; (key in $scope.data){ $scope.data[key].avg = i++; }; } ,3000) }); app.directive('draw', function() { homecoming { scope: { value: "@" }, link: function (scope, element, attrs){ if (attrs.value != 0) { var svgcontainer = d3.select(element[0]).append("svg").attr("width", 200).attr("height", 200); var circle = svgcontainer.append("circle").attr("cx", 30).attr("cy", 30).attr("r", 20); } } } });
here plunker problem reproduced: http://plnkr.co/edit/v62wngzpmsbwh6zshccm?
change directive to:
app.directive('draw', function() { homecoming { scope: { value: "=" //<--- }, link: function (scope, element, attrs){ scope.$watch("value", function(val) { //draw stuff val }); } }
}
and html be:
<body ng-app="app" ng-controller="mainctrl"> <div ng-repeat="val in data"> <div draw value="val.avg">{{val.avg}}</div> </div> </body>
here updated plunkr: http://plnkr.co/edit/pin8iy77qy5n4thqiclp?p=preview
javascript angularjs d3.js angularjs-directive angularjs-ng-repeat
Comments
Post a Comment