There is a directive:
angular.module('analyticsMenu').directive('chartJs', ['$timeout', function($timeout) { return { restrict: 'E', scope: { type: '=', width: '=', height: '=', data: '=', options: '=' }, templateUrl: 'analytics-menu/chart-js/chart-js.template.html', link: function($scope, $element, $attr) { var newChart = function() { var ctx = $element.find('canvas')[0]; var chart = new Chart(ctx, { type: $scope.type, data: $scope.data, options: $scope.options }); }; var watchData = function() { return JSON.stringify($scope.data); }; $scope.$watch('watchData', updateWhenDataChange, true); var updateWhenDataChange = function(newVal, oldVal) { console.log(123); } $timeout(newChart, 0); } } }]);
When changing the data attribute (or rather, when changing any of the parameters of the objects that I pass to the directive as a parameter), I need to redraw the graph.
At first, I just tried to write:
$scope.$watch('data', updateWhenDataChange, true);
But this led to an error:
angular.js: 13920 RangeError: Maximum call stack size exceeded
$watch
executes the string passed to it in the context of the Osprey for which it is called, watchData _ is not in the Osprey, respectively$scope.watchData
scope.watchData never changes and always _undefiend . If you add a working example, you can see what was wrong with data - Grundy