vishnu
vishnu

Reputation: 4599

ionic open accordion by default from controller

I have implemented ionic accordion effect using the following code. It was working fine as expected, but i want to open the first accordion by default.

    <ion-item class="item-stable"
              ng-click="toggleGroup(0)"
              ng-class="{active: isGroupShown(0)}">
              <i class="icon" ng-class="isGroupShown(0) ? 'ion-minus' : 'ion-plus'"></i>
                    &nbsp;
                        Permanant Address
    </ion-item>

    <div class="item-accordion" ng-show="isGroupShown(0)">
         ---------
    </div>

<ion-item class="item-stable"
              ng-click="toggleGroup(1)"
              ng-class="{active: isGroupShown(1)}">
              <i class="icon" ng-class="isGroupShown(1) ? 'ion-minus' : 'ion-plus'"></i>
                    &nbsp;
                        Temporary Address
    </ion-item>

    <div class="item-accordion" ng-show="isGroupShown(1)">
         ---------
    </div>

controller

 $scope.toggleGroup = function(group) {
    if ($scope.isGroupShown(group)) {
      $scope.shownGroup = null;
    } else {
      $scope.shownGroup = group;
    }
  };
  $scope.isGroupShown = function(group) {
    return $scope.shownGroup === group;
  };

Upvotes: 2

Views: 1533

Answers (1)

Leandro Zubrezki
Leandro Zubrezki

Reputation: 1150

Just add this line at the end of the for loop:

  $scope.shownGroup = $scope.groups[0];

Upvotes: 4

Related Questions