Chartjs-Render Chart on second template by clicking icon on the first template

0👍

is there any relation between the controllers ? Are they parent/child ? You could use AngularJs events ($emit, $broadcast) if so.

If not, you might want to use a common parent ancestor, (if there isn’t any, you can use rootScope`) to fire an event when clicking, and using $scope.$on to listen that event and draw the chart. Something like

Template1 HTML

ng-click="drawChart()"

Template1 Controller

$scope.drawChart = function(){
      // $root scope must be injected in the controller. Use the name you prefer
      $rootScope.$broadcast('draw-custom-chart');
};

Template2Controller

$scope.$on('draw-custom-chart', function($event){
    $event.stopPropagation();
    $scope.daily();
});

A better aproach, I believe, anyway is to move the daily() function into a service, and inject into the Template1Controller and call it from there. If you also need it in the Template2Controller, you can inject it there as well.

Leave a comment