13
我使用http://angular-ui.github.com/bootstrap/的手風琴指令,我需要在頁眉部分有兩個按鈕。在頁眉部分帶有按鈕的角度UI手風琴
- 添加 - 創建原創下相同的手風琴。
- 移除 - 取出手風琴。 (第一個手風琴不能被刪除 - 禁用刪除按鈕)。
我是AngularJS的新手,請幫我實現這個目標。
我使用http://angular-ui.github.com/bootstrap/的手風琴指令,我需要在頁眉部分有兩個按鈕。在頁眉部分帶有按鈕的角度UI手風琴
我是AngularJS的新手,請幫我實現這個目標。
看到一個工作plunker。
你只需要添加和控制器
$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, 0, newGroup);
};
$scope.removeGroup = function(idx, e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
$scope.groups.splice(idx, 1);
};
,併爲您的HTML一個ng-repeat
刪除功能:
<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, group, $event)">+</button>
<button class="btn btn-small" ng-click="removeGroup($index, $event)" ng-show="$index">-</button>
</accordion-heading>
{{group.content}}
</accordion-group>
</accordion>
把眼前這個e.originalEvent.cancelBubble = TRUE;
$scope.addGroup = function(idx, group, e) {
if (e) {
e.originalEvent.cancelBubble=true;
}
var newGroup = angular.copy(group);
newGroup.no = $scope.groups.length + 1;
$scope.groups.splice(idx + 1, 0, newGroup);
};
$scope.removeGroup = function(idx, e) {
if (e) {
e.originalEvent.cancelBubble=true;
}
$scope.groups.splice(idx, 1);
};
嗨Bekos,這是我正在尋找。你解決了我的問題。謝謝你 – user2801604
非常感謝!我不知道$ event var,所以這非常有幫助! –