0

I have a $watchgroup in angularjs in which I have two values, primaryApplicationChartData and secondaryApplicationChartData. The watchgroup gets called when both of them change.

I want to make sure that the code inside $watchgroup i.e.,drawStockChart() func gets called only once even though both chart data change.

Can anyone give some idea on how to do it?

Thanks.

scope.$watchGroup(['primaryApplicationChartData', 'secondaryApplicationChartData'], function(newValues, oldValues, scope) {
        console.log("chartData has changed");
        drawStockChart();
});
T Ravi Theja
  • 63
  • 1
  • 11
  • Possible duplicate of [Unbinding $watch in angularjs after called](https://stackoverflow.com/questions/19394204/unbinding-watch-in-angularjs-after-called) – Syed mohamed aladeen May 17 '19 at 07:03
  • What changes the two scope properties? Is there a single event that causes the change? If the data comes from two server request, the code can use [$q.all](https://docs.angularjs.org/api/ng/service/$q#all) to wait for the two sever requests. – georgeawg May 17 '19 at 21:01
  • What about this snippet: `if(!$scope.flag) { drawStockChart(); $scope.flag = true; }` – Slava Utesinov May 21 '19 at 06:19

0 Answers0