[Chartjs]-Nesting directives and using the data inside the local scope

0👍

With local scope parameters defined by “@” you only get one way binding of String values into the directive. There is no way back and such as the Arrays you set the scope variables to are only local to the directive. Plus @ only allows string values, no objects or arrays.

Instead define your directive like this (from your pastebin):

fitAdmin.directive('exercice', function(Client) {
  return {
    template: '<canvas id="bar" class="chart chart-bar" data="poidsExo" labels="exoLabel"></canvas> ',
    restrict: 'EA',
    scope: {
      poidsExo: '=',
      exoLabel: '=',
  },
  link : function (scope, element, attrs) {

    Client.getClientResultsExercice(attrs.id, attrs.name).then (function (data) {
      scope.poidsExo = [];
      scope.exoLabel = [];
      var dateTemp;
      angular.forEach(data, function (data) {
        if (data.date !== dateTemp) {
          scope.poidsExo.push(data.poids);
          scope.exoLabel.push(data.date);
        dateTemp = data.date;
        };
      });
    })
  },

};
});

Leave a comment