V
V
vvrider2016-01-20 14:34:03
Angular
vvrider, 2016-01-20 14:34:03

How to sort only even items in an array using ng-repeat?

Hello,
there is a json that is parsed from api.

"dishes": [
{
"name": "apple salat",
"calories": 100,
"proteins": 30,
"carbohydrates": 25,
"fats": 30,
"food_items": [
{
"name": "apple",
"calories": 100,
"proteins": 30,
"carbohydrates": 25,
"fats": 30
},
1,
{
"name": "fruit salat",
"calories": 100,
"proteins": 30,
"carbohydrates": 25,
"fats": 30,
"food_items": [
{
"name": "apple",
"calories": 100,
"proteins": 30,
"carbohydrates": 25,
"fats": 30
},
2
]

How to use ng-repeat to extract every even element of an array?
I know how to do it with the for 'th function, but I would like to know, or can I somehow pull it out using ng-repeat.
something in the form:
<li ng-repeat=" food_items in data.dishes track by $index">{{ $even.name }}</li>

To be honest, I don’t have much experience with ng-repeat, so I’m trying to experiment and try to understand whether something like this can be done.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2016-01-20
@AMar4enko

Filter the array beforehand and output

N
Nicholas, 2016-01-20
@healqq

You can pervert and write a custom filter, but believe me, you shouldn't do that. Prepare data in the controller if possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question