我一直在使用Angular ui-bootstrap
。在此处oneAtATime
即使值设置为true
也无法正常工作。这是我的代码。
<div ng-repeat="group in groups track by group.key">
<uib-accordion close-others="oneAtATime">
<uib-accordion-group>
<uib-accordion-heading >
<div>
{{ group.title }}
<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</div>
</uib-accordion-heading>
</uib-accordion-group>
</uib-accordion>
</div>
plnkr链接。
答案 0 :(得分:2)
您的HTML结构错误。应该只有一个uib-accordion
元素和多个uib-accordion-group
元素。所以只需改变你的代码:
<uib-accordion close-others="oneAtATime">
<uib-accordion-group ng-repeat="group in groups track by group.key">
<uib-accordion-heading>
<div>
{{ group.title }}
<i class="pull-right glyphicon"
ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</div>
</uib-accordion-heading>
</uib-accordion-group>
</uib-accordion>
我所做的只是将您的ng-repeat
表达式移到uib-accordion-group
元素中。
请参阅下面的工作示例:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function($scope) {
$scope.oneAtATime = true;
$scope.groups = [{
title: 'Dynamic Group Header - 1',
content: 'Dynamic Group Body - 1',
key: 1
}, {
title: 'Dynamic Group Header - 2',
content: 'Dynamic Group Body - 2',
key: 2
}];
$scope.items = ['Item 1', 'Item 2', 'Item 3'];
$scope.addItem = function() {
var newItemNo = $scope.items.length + 1;
$scope.items.push('Item ' + newItemNo);
};
$scope.status = {
isCustomHeaderOpen: false,
isFirstOpen: true,
open: true,
isFirstDisabled: false
};
});
&#13;
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<script src="script.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="AccordionDemoCtrl">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="oneAtATime">Open only one at a time
</label>
</div>
<uib-accordion close-others="oneAtATime">
<uib-accordion-group ng-repeat="group in groups track by group.key">
<uib-accordion-heading>
<div>
{{ group.title }}
<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</div>
</uib-accordion-heading>
</uib-accordion-group>
</uib-accordion>
</div>
</body>
</html>
&#13;