我正在使用
http://angular-ui.github.com/bootstrap/的手风琴指令,我需要在标题部分有两个按钮.
>添加 – 在原创下方创建完全相同的手风琴.
>删除 – 删除手风琴. (第一把手风琴无法移除 –
禁用“删除”按钮).
我是AngularJS的新手,请帮我实现这一点.
看工作
plunker.
原文链接:/angularjs/142872.html$scope.addGroup = function(idx,group,e) { if (e) { e.preventDefault(); e.stopPropagation(); } var newGroup = angular.copy(group); newGroup.no = $scope.groups.length + 1; $scope.groups.splice(idx + 1,newGroup); }; $scope.removeGroup = function(idx,e) { if (e) { e.preventDefault(); e.stopPropagation(); } $scope.groups.splice(idx,1); };
和你的html的ng重复:
<accordion close-others="oneAtATime"> <accordion-group heading="{{group.title}}" ng-repeat="group in groups"> <accordion-heading> {{ group.title }} ({{group.no}}) <button class="btn btn-small" ng-click="addGroup($index,$event)">+</button> <button class="btn btn-small" ng-click="removeGroup($index,$event)" ng-show="$index">-</button> </accordion-heading> {{group.content}} </accordion-group> </accordion>