Reputation: 61
I have multiple divs which are generated with ng-repeat from a controller which loads content from api.
Controller:
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>
With example above I can show/hide single div on a click, but how would I show/hide multiple divs ? I want something like this jsfiddle example
Upvotes: 1
Views: 2355
Reputation: 4611
It should work
<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>
Upvotes: 1