0

I am having little issue. I am trying to display some data using ng-repeat like that:

ng-repeat="color in apples[{{index}}].color"

where

$scope.index = $stateParams.index;

However, I get a a syntax error.

What is a proper way to dynamically add index to array in this example?

1 Answer 1

2

Just use loop index:

ng-repeat="color in apples[$index].color"

or

ng-repeat="color in apples[index].color"
Sign up to request clarification or add additional context in comments.

5 Comments

This doesn't work for me: when I try to display values below the ng-repeat for color, I have an empty object. ( I display values as {{color}})
And in HTML code I have: <!-- ngRepeat: color in apples[index].color -->
What is the error message? Can you create a fiddle?
Alright, this worked :) I had to rename index to pp.index, as I use controller as syntax :)
You can use ng-repeat only on the iterable items. Check if apples[index] has any property attribute. Also share complete code. It is hard to understand whether apples is an array or object

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.