Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make by default accordion to make open first element?

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

like image 678
Michael Avatar asked May 07 '16 19:05

Michael


1 Answers

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

like image 187
Pankaj Parkar Avatar answered Nov 15 '22 06:11

Pankaj Parkar