离子开放式手风琴默认来自控制器

时间:2015-11-26 03:37:34

标签: angularjs ionic

我使用以下代码实现了离子手风琴效果。它按预期工作正常,但我想默认打开第一支手风琴。

    <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>

控制器

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

1 个答案:

答案 0 :(得分:4)

只需在for循环的末尾添加此行:

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