sridharan sridharan - 2 months ago 231
AngularJS Question

how to create dropdown menu in Ionic Side menu?

How to create sub menu in ionic framework?
I am new to both AngularJs and ionic framework. I am trying to create a drop down list component. I was able to do that with the below code.enter image description here



<ion-side-menu side="left">
<ion-content class="has-expanded-header">
<ion-list>
<ion-item nav-clear menu-close class="item-icon-left" ui-sref="main.dashboard">
<i class="icon ion-ios-speedometer"> </i>
Dashboard
</ion-item>
<ion-item nav-clear menu-close class="item-icon-left item-icon-right" ui-sref="main.accounts">
<i class="icon ion-accounts ion-ios-arrow-right"> </i>
Accounts
</ion-item>
<ion-item nav-clear menu-close class="item-icon-left" ui-sref="main.accounts">
<i class="icon ion-accounts"> </i>
sub Accounts 1
</ion-item>
<ion-item nav-clear menu-close class="item-icon-left" ui-sref="main.accounts">
<i class="icon ion-accounts"> </i>
sub Accounts 2
</ion-item>
</ion-list>
</ion-content>
</ion-side-menus>




Answer

html code:

<ion-list>
        <div ng-repeat="group in groups">
          <ion-item class="item-stable"
                    ng-click="toggleGroup(group)"
                    ng-class="{active: isGroupShown(group)}">
              <i class="icon" ng-class="isGroupShown(group) ? 'ion-minus' : 'ion-plus'"></i>
            &nbsp;
            Group {{group.name}}
          </ion-item>
          <ion-item class="item-accordion"
                    ng-repeat="item in group.items"
                    ng-show="isGroupShown(group)">
            {{item}}
          </ion-item>
        </div>
      </ion-list>

controller code:

 $scope.groups = [];
  for (var i=0; i<10; i++) {
    $scope.groups[i] = {
      name: i,
      items: []
    };
    for (var j=0; j<3; j++) {
      $scope.groups[i].items.push(i + '-' + j);
    }
  }

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

hope this may help you :)