1

I looking for how to display sum of result from array without use a javascript in my controller.

My object:

usages:[
       { frontends: [{errors: 1}, {errors: 2}, {errors: 3}] },
       { frontends: [{errors: 2}, {errors: 1}, {errors: 1}] }
]

My HTML template:

<tr ng-repeat="usage in foo.usages">
  <span>{{usage.frontends ???? }}&thinsp;%</span> 
</tr>

I want this result:

+-------+
+   6   +
+-------+
+   4   +
+-------+

1 Answer 1

1

Here is a solution using ng-init:

<table>
    <tr ng-repeat="usage in usages" ng-init="total = {}" >
      <td ng-repeat="front in usage.frontends" ng-init="total.errors = front.errors + total.errors">
          <div ng-if="$last">{{ total.errors }}</div>
      </td> 
    </tr>
  </table>

Check the working demo: DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.