我有多个div,它们是从控制器生成的ng-repeat,它从api加载内容。
控制器:
app.controller('exampleController', [ '$http','$scope', function($http, $scope) {
var tmp=this;
tmp.data=[];
$scope.collapsed=false;
$http.get(url)...
}]);
HTML:
//ng-repeat limited to 1 for this example
<div class="someClass" ng-repeat="data in myCtrl.data | limitTo: 1">
<div ng-model="collapsed" ng-click="collapsed=!collapsed"> some div content </div>
<div class="hidden" ng-show="collapsed"> some hidden div </div>
</div>
上面的示例我可以在点击时显示/隐藏单个div,但是如何显示/隐藏多个div?我想要像this jsfiddle example
这样的东西答案 0 :(得分:1)
应该有效
<div class="someClass" ng-repeat="data in myCtrl.data | limitTo: 1">
<div ng-model="collapsed[$index]" ng-click="collapsed[$index]=!collapsed[$index]"> some div content </div>
<div class="hidden" ng-show="collapsed[$index]"> some hidden div </div>
</div>