这似乎应该是如此简单,但我的大脑正在爆炸。这是我想用角度来实现的,我有我的购物清单
app.controller("Destroyer", function($scope) {
$scope.shoppingList = [
{name: 'Milk'},
{name: 'Eggs'},
{name: 'Bread'},
{name: 'Cheese'},
{name: 'Ham'}
];
});
在我的模板中,我想访问第3项,例如
{{ shoppingList.name[$index == 2] }}
我该怎么做?感谢
编辑:回答{{shoppingList [2] .name}}
答案 0 :(得分:1)
if you know the index you can give like this
{{shoppingList[2].name}}
or in ng-repeat
<div ng-repeat="list in shoppingList " ng-show="$index==2">{{list.name}}</div>