Hassebo
Hassebo

Reputation: 3

ng-repeat won´t work with my array

I´m a newbie to Angular Js and I´m trying to get the ingredients from an array using ng-repeat on this format:

<ng-repeat="ingredient in recipe['_source']['ingridients'] track by $index">{{ ingredient }}

The array looks like this:

ingredients: 
  Array[6]
    0: "1/4 cup ice"
    1: "1 fluid ounce vodka"
    2: "1/2 fluid ounce Galliano liqueur"
    3: "2 fluid ounces citrus flavored energy drink (e.g. Red Bull™)"
    4: "2 fluid ounces lemon-lime soda"
    5: "1 teaspoon honey"        

Does someone know the syntax how to reach the objects in the array with that format on the array-variable? I´ve been trying multiple ways to get the objects, but it won´t work.

It works to write out single variables (for example {{recipe['_source']['name']}}).

Upvotes: 0

Views: 42

Answers (2)

Muhammad Ahsan Ayaz
Muhammad Ahsan Ayaz

Reputation: 1947

try this :

<ul>
   <li ng-repeat="ingredient in recipe track by $index">{{ ingredient }}</li>
<ul>

where your array would look something like

var recipe = [
    "1/4 cup ice",
    "1 fluid ounce vodka",
    "1/2 fluid ounce Galliano liqueur",
    "2 fluid ounces citrus flavored energy drink (e.g. Red Bull™)",
    "2 fluid ounces lemon-lime soda",
    "1 teaspoon honey"   
]

Upvotes: 0

rewritten
rewritten

Reputation: 16435

It seems just a mistype, you have written ingridients instead of ingredientes. If possible, use actual tags and attributes instead of angular-provided tags.

<div ng-repeat="ingredient in recipe._source.ingredients track by $index">
  {{ ingredient }}
</div>

Upvotes: 1

Related Questions