Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs UI collapse in ngRepeat

I am trying to embed some collapsible panels in a ngRepeat. This is what I have:

<div class="panel panel-default" ng-repeat="element in elements">
 <div class="panel-heading">
  {{element.name}}
  <button value="Collapse" ng-click="element.isCollapsed != element.isCollapsed"></button>
 </div>
 <div class="panel-body" collapse="element.isCollapsed">
  Content
 </div>
</div>

Now, when I click on the button, the collapse doesn't work.

From the documentation I understand that the repeater creates a scope for every element.

And the attribute collapse of the panel-body should get the same scope, right?

It seems that the scope.$watch in the collapse directive is not working properly.

like image 803
Enrico Avatar asked Feb 13 '23 18:02

Enrico


1 Answers

Please check the updated fiddle: http://jsfiddle.net/nZ9Nx/9/

I have created the app and injected ui-bootstrap in it to have the collapse working.

angular.module('test', ['ui.bootstrap']);
like image 152
V31 Avatar answered Feb 24 '23 11:02

V31