Expression in data attribute for angular chart.js

Hi I have tried using an expression inside the data attribute like this

      <div ng-repeat="item in items">
        <canvas data="getTheData(item.value)"></canvas>
     </div>

and in the controller

var getData = {
    first: function(){ return angularFactory.getData() };
    second: function(){ return angularFactory.getData() };
}


$scope.getTheData = function(value){
  getData[value]().then(function(data){
      console.log(data);
    });
};

my plan is to get only the needed data from factories based on what items the user load.

the problem is this is resulting in [$rootScope:infdig] with a log that never stops even though I just have one item in the "item" list.

Am I doing this wrong?

Answers


You could have something like this, I'm not sure this will work or not

Call an getTheData on rendering of DOM, you should pass item inside that method instead of item.value

<div ng-repeat="item in items" ng-init="getTheData(item)">
    <canvas data="item.data"></canvas>
</div>

Code

$scope.getTheData = function(item){
  getData[item.value]().then(function(data){
      item.data = data;
      console.log(data);
    });
};

So inside the success of getData function you need to set item.data value that will get passed to canvas data attribute.


Need Your Help

Ranking items in a list with LINQ

c# .net linq

I am trying to figure out a way to rank items in a list, and hold the results in an object or another list. I know about the orderby method, but I don't exactly know how to go about creating a

Using a user defined variable within a function? (Ruby, Watir)

ruby watir

I'm creating drag and drop feature that depends on upon ID for placement, it works perfectly fine, but I need the status of task to be user defined so the user will have control of where something ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.