Question

The html template contains a list of items filtered

        <ul class="gift_info">
         <li ng-repeat="code in codes | filter:{id_id:detail.id}">{{code.discount}}</li>
        </ul>

Below this list there is a button with code like

<button type="button" ng-click="add_something(repeat_expression_needed)">Add more</button>

The goal is to feed the items from ng-repeat above to function below as a param (collection, array, whatever). Is it doable via mere template directives or some controller tricks need to be involved?

Was it helpful?

Solution

The code using the method @Jonathan pointed out

<ul class="gift_info">
    <li ng-repeat="code in (filteredCodes = (codes | filter: {id_id:detail.id})">{{code.discount}}</li>
</ul>

and then

<button type="button" ng-click="add_something(filteredCodes)">Add more</button>

OTHER TIPS

You can use an expression inside of the ng-repeat to assign a variable that will hold the collection and will then be available inside the scope.

See answer: How can I obtain the result array of an angular "| filter" expression in a variable?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top