darKnight
darKnight

Reputation: 6481

Use parent scope value in filter ng-repeat

I have some Angular code which uses nested ng-repeat like this:

 <div ng-repeat="sym in transData.trades | unique:'Symbol'">
    {{sym.Symbol}}
    <div ng-repeat="trans in transData.trades | filter: { Symbol: 'ParentValue' } | orderBy: ['Action']">
        <span>{{trans.Action}}</span>
        <span>{{trans.TxnId}}</span>
        <span>{{trans.Quantity}}</span>
        <span>{{trans.Price}}</span>
        <span>{{trans.MarketValue}}</span>
    </div>
</div>

I want to filter the second ng-repeat by the parent ng-repeat's scope value {{sym.Symbol}} (that's what ParentValue is representing in the second ng-repeat). How can I do that? Using filter: { Symbol: {{$parent.sym.Symbol}} } does not work.

Upvotes: 0

Views: 102

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

Just use sym.Symbol,

<div ng-repeat="sym in transData.trades | unique:'Symbol'">
    {{sym.Symbol}}
    <div ng-repeat="trans in transData.trades | filter: {trans : {Symbol: sym.Symbol}} | orderBy: ['Action']">
        <span>{{trans.Action}}</span>
        <span>{{trans.TxnId}}</span>
        <span>{{trans.Quantity}}</span>
        <span>{{trans.Price}}</span>
        <span>{{trans.MarketValue}}</span>
    </div>
</div>

DEMO

Upvotes: 1

Related Questions