0

In my html (.ng-template) I have an array, on which a filter is applied. I want to apply a map function to the result of this filter function (It's too expensive to apply it to the whole array before applying the filter). The older versions of angularjs allowed me to do so by

<ng-repeat = 'item in array.$filter(filterFunc).map(mapFunc).$orderBy("orderFunc()")'>

But with the new syntax (v 1.0.5) I am not able to do this.

<ng-repeat = 'item in array|filter:filterFunc|orderBy:"orderFunc()"'>

I do don't understand how do I apply map function to this. Is there any way to accomplish this?

1 Answer 1

1

Templates are hard to test, do not write any business logic in the templates, besides, these functions will create a new copy of your array and apply map function every time in every $digest phase.

You should do this in your controller and use ngRepeat within that.

function MyCtrl ($scope, $filter) {
  var fullArray = [1,2,3];
  var otherArray = $filter(filterFunc).map(mapFunc);
}

.

<div ng-repeat="item in otherArray | orderBy:orderFn"></div>

You can also order the array in the controller.

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

1 Comment

Strangely, I had the same solution, and I actually was trying to move that logic in the template.....sleepy idiot of me!

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.