Last active
October 24, 2019 08:24
-
-
Save tithi021/3cf11532a30f2954b5831e2366ce2ea9 to your computer and use it in GitHub Desktop.
Ionic 3 Accordion Sidemenu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ViewChild } from '@angular/core'; | |
import { Nav, Platform, MenuController } from 'ionic-angular'; | |
import { StatusBar } from '@ionic-native/status-bar'; | |
import { SplashScreen } from '@ionic-native/splash-screen'; | |
import { MenuProvider } from '../providers/menu/menu'; | |
@Component({ | |
templateUrl: 'app.html' | |
}) | |
export class MyApp { | |
@ViewChild(Nav) nav: Nav; | |
rootPage: any = 'HomePage'; | |
pages: any; | |
// Selected Side Menu | |
selectedMenu: any; | |
constructor(public platform: Platform, | |
public statusBar: StatusBar, | |
public splashScreen: SplashScreen, | |
public menuProvider: MenuProvider, | |
public menuCtrl: MenuController) { | |
this.initializeApp(); | |
} | |
initializeApp() { | |
this.platform.ready().then(() => { | |
// Okay, so the platform is ready and our plugins are available. | |
// Here you can do any higher level native things you might need. | |
this.getSideMenuData(); | |
this.statusBar.styleDefault(); | |
this.splashScreen.hide(); | |
}); | |
} | |
getSideMenuData() { | |
this.pages = this.menuProvider.getSideMenus(); | |
} | |
openPage(page, index) { | |
// Reset the content nav to have just this page | |
// we wouldn't want the back button to show in this scenario | |
if (page.component) { | |
this.nav.setRoot(page.component); | |
this.menuCtrl.close(); | |
} else { | |
if (this.selectedMenu) { | |
this.selectedMenu = 0; | |
} else { | |
this.selectedMenu = index; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ion-menu [content]="content"> | |
<ion-header> | |
<ion-toolbar> | |
<ion-title>Menu</ion-title> | |
</ion-toolbar> | |
</ion-header> | |
<ion-content> | |
<ion-list> | |
<ion-item ion-item *ngFor="let p of pages; let i=index" (click)="openPage(p, i);"> | |
<ion-row> | |
<!-- Parent Pages --> | |
<ion-col col-9 class="menu-name"> | |
<span ion-text> | |
{{p.title}} | |
<ion-icon [name]="selectedMenu == i? 'arrow-down' : 'arrow-forward'" *ngIf="p.subPages" float-right></ion-icon> | |
</span> | |
<!-- Child Pages --> | |
<ion-list no-lines [hidden]="selectedMenu != i"> | |
<ion-item no-border *ngFor="let subPage of p.subPages;let i2=index" text-wrap (click)="openPage(subPage)"> | |
<ion-row> | |
<ion-col col-10 class="menu-name"><span ion-text color="color2"> {{subPage.title}}</span></ion-col> | |
</ion-row> | |
</ion-item> | |
</ion-list> | |
</ion-col> | |
</ion-row> | |
</ion-item> | |
</ion-list> | |
</ion-content> | |
</ion-menu> | |
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus --> | |
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank u so much it is working absolutely.....