I use bootstrap accordion in my project.
Here is working fiddler .
Here is HTML code:
<div ng-app="myapp">
<div ng-controller="AccordionDemoCtrl">
<uib-accordion close-others="oneAtATime">
<uib-accordion-group ng-repeat="group in groups" is-open="isOpen">
<uib-accordion-heading>
<div class="text-center">
<strong>{{group.title}}</strong>
<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isOpen, 'glyphicon-chevron-right': !isOpen}"></i>
</div>
</uib-accordion-heading>
{{group.content}}</uib-accordion-group>
</uib-accordion>
</div>
</div>
Here is controller:
var app = angular.module('myapp', ['ui.bootstrap', 'ngAnimate'])
app.controller('AccordionDemoCtrl', function($scope) {
$scope.groups = [{
title: "Dynamic Group Header - 1",
content: "Dynamic Group Body - 1"
}, {
title: "Dynamic Group Header - 2",
content: "Dynamic Group Body - 2"
}, {
title: "Dynamic Group Header - 3",
content: "Dynamic Group Body - 3"
}];
});
I tryed to use this row:
is-open="true"
Like that:
<uib-accordion-group heading="{{group.title}}" ng-repeat="group in groups" is-open="true">{{group.content}}</uib-accordion-group>
But it opens by default all items.
How can I make by default accordion to make open only first element?
P.S. Here is updated plunker
Do take use of $first
of ng-repeat
directive to open only 1st accordion like is-open="$first"
Markup
<uib-accordion close-others="oneAtATime">
<uib-accordion-group heading="{{group.title}}"
ng-repeat="group in groups"
is-open="$first">
{{group.content}}
</uib-accordion-group>
</uib-accordion>
Preview Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With