我有一个带有“雪佛龙”图标的手风琴,点击时切换为指向上或下,这是通过ng-click和ng-class完成的.手风琴只允许一个面板同时打开 – 所以当我点击一个关闭的面板时,打开的面板关闭.但是如何切换打开面板上的V形图标,并通过ng-click关闭?
最初我可以用DOM操作等来做,但由于这是角度的局部视图我不能这样做.
码:
<div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#collapSEOne" ng-click="firstpaneisopen=!firstpaneisopen"> <i class="glyphicon" ng-class="{'glyphicon-chevron-up': firstpaneisopen,'glyphicon-chevron-down': !firstpaneisopen}"></i> Collapsible Group Item #1 </a> </h4> </div> <div id="collapSEOne" class="panel-collapse collapse in"> <div class="panel-body"> Body </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" ng-click="secondpaneisopen=!secondpaneisopen> <i class="glyphicon" ng-class="{'glyphicon-chevron-up': secondpaneisopen,'glyphicon-chevron-down': !secondpaneisopen}"></i> Collapsible Group Item #2 </a> </h4> </div> <div id="collapseTwo" class="panel-collapse collapse"> <div class="panel-body"> Body </div> </div> </div> </div>
我建议您从AngularUI团队查看“UI Bootstrap”.它是“用纯AngularJS编写的Bootstrap组件”的集合.
http://angular-ui.github.io/bootstrap/
他们的网站上有一个示例,显示他们的Accordion指令使用ng-class来切换V形图标.
http://angular-ui.github.io/bootstrap/#/accordion
他们的指令还具有close-others属性,如果属实,将确保任何时候只打开一个面板.
<accordion close-others="true">