我有ng-repeat
项目列表,我需要显示“状态”文本旁边的某个事件项目(如点击等),我发现我可以使用$index
,但无法理解如何在控制器中使用它。 HTML:
<div ng-repat = 'item in items'> {{item}} <span ng-show = 'ShowItemStatus[$index]'> Status </span> </div>
我使用控制器内的NG出现,它看起来像:
$scope.ItemStatus = false
我怎么能控制器内得到索引,以便它会看起来像$scope.ItemStatus[$index] = false
- 这不是对我的作品。
如果我通过id遍历我的控制器中的项目我可以如何将此ID添加到'$ scope.ItemStatus'? '$ scope.ItemStatus [id]'不起作用。 – Shulte 2015-02-24 14:52:54
看@DeOldSax的答案。做遍历看起来像这样http://jsfiddle.net/g5cxmf9f/ – goreorto 2015-02-24 15:27:52
也许我不清楚。在我的情况下,我使用的自定义服务提供商,点击显示此“状态”消息,然后消息淡出。所以我当前的控制器看起来像'$ scope.ItemStatus = ServiceProvider'。我的想法是根据项目id使这个'ItemStatus'动态化,像'$ scope.ItemStatus1','$ scope.ItemStatus2'等。 – Shulte 2015-02-24 15:39:08