我是Angular Js的新手,我正试图用这种格式的ng-repeat从数组中获取成分:
<ng-repeat="ingredient in recipe['_source']['ingridients'] track by $index">{{ ingredient }}
数组如下所示:
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"
有人知道如何在数组变量上以该格式到达数组中的对象的语法吗?我一直在尝试多种方法来获取对象,但它不起作用。
它可以写出单个变量(例如{{recipe['_source']['name']}}
)。
答案 0 :(得分:1)
这似乎只是一种错误,你写的是ingridients
而不是ingredientes
。如果可能,请使用实际标记和属性,而不是使用角度提供的标记。
<div ng-repeat="ingredient in recipe._source.ingredients track by $index">
{{ ingredient }}
</div>
答案 1 :(得分:0)
试试这个:
<ul>
<li ng-repeat="ingredient in recipe track by $index">{{ ingredient }}</li>
<ul>
你的数组看起来像
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"
]