georgiy.zhuravlev
georgiy.zhuravlev

Reputation: 475

Angular nested and filtered ng-repeat totals

I have the list of customers and the orders for every customer. It looks like this:

  <ul>
    <li ng-repeat="customer in data.customes" | filter:customerFilterFn ">
     {{customer.name}} {{??? total should change depending on nested FILTERED data???}}
      <ul>
        <li ng-repeat="order in customer.orders" | filter:orderFilterFn ">
        {{order.id}} {{order.sum}}
        </li>
      </ul>  
    </li>
  </ul>

As you see, both lists are filtered by their own functions (for the orders it is a date range).

What is the best approach to get the customer's total for the filtered set of orders?

Upvotes: 0

Views: 31

Answers (2)

Dee
Dee

Reputation: 43

Actually, you can use the same orderFilterFn for filtering orders before ng-repeat. Something like this: http://codepen.io/anon/pen/xwgYZj

If performance is very important, you can filter orders only once: http://codepen.io/anon/pen/bVgLjB

Upvotes: 1

akhurad
akhurad

Reputation: 204

You could use the $index for the ng-repeat directive. This way you get each order's value, and then you can maintain a $scope variable for the customer's total.

Upvotes: 1

Related Questions