Chartjs-$scope variable not updating when factory object changes AngularJS

0👍

You’re already exposing chartData through your factory so now you can add a $scope.chartData variable to your controller that references the factory’s chartData array directly.

$scope.chartData = chartFactory.chartData;

Now you have a variable in your controller’s $scope that references the chartData, so any changes in one will be reflected in the other, both variables are now referencing the same array (object).

I wasn’t sure if you would have to re-render the chart, but having a quick read of the docs for Angular Chart.js it does say that it updates automatically so you should be fine.

All charts are reactive and will update automatically when data
changes.”

Leave a comment