1

Yo everyone.

I've got a .json file structured like that :

var var1 =
[ { "a":"soluce1",
    "b": 
           [ { "user1" : "username1",
               "ba" : "1" },
             { "user2" : "username2",
               "ba" : "2" } ],
    "c":"useless"
} ];

, my .html file :

<tr ng-repeat="varhtml in var1">
    <td>{{varhtml.b[0].ba}}</td>
</tr>

and it appears :

1


I know that all is good at first. For the next step, I would display

3

, result of (1+2 : (ba+ba and more arrays if needed...)). At first glance I thought that was not really difficult but I don't know what I need to do with <td>{{varhtml.b[0].ba}}</td> or others files to have this wish.

Thank you in advance for the helps.

WORKING RESULT :

$scope.additionNumber = function (varhtml) {    
var total = 0;  
  angular.forEach (varhtml.b, function (ligne) {        
     total += ligne.ba;     
  });   
return total; 
}


<tr ng-repeat="varhtml in var1">
    <td><span ng-bind="additionNumber(varhtml)"></span></td>
</tr>
guish
  • 29
  • 10

1 Answers1

0

Why not precalculate the value and set that on the scope?

Don't entirely understand your question but if you want a sum of all the values then you could precalculate the value, or if it needs to be dynamic, calculate it with a method?

$scope.calculateValue = function() {
    // loop through array and add up the values
    // then return the value
    return value;
};

<span ng-bind="calculateValue()"></span>

If you just need to xn + xn+1 then you could use a for loop and loop through b and do some logic?

Community
  • 1
  • 1
Adam K Dean
  • 7,387
  • 10
  • 47
  • 68