ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Dynamically add items to Ionic 2 side menu

Open Tusharbalar opened this issue 9 years ago • 7 comments

I am using latest version of ionic 2.

Ionic version: 2.1.8

I want to add item dynamically in a sidebar.

app.component.ts;

export class MyApp {

  pages: Array<{title: string, component: any, icon: any }>;

  this.pages = [
  { title: 'Dashboard', component: DashboardComponent, icon: 'ios-home-outline' },
  { title: 'Complaints', component: ComplaintPage, icon: 'ios-sad-outline' },
  { title: 'Suggestions', component: SuggestionPage, icon: 'md-bulb' },
  { title: 'Appreciations', component: AppreciationPage, icon: 'ios-thumbs-up-outline' },
  { title: 'Poll', component: PollPage, icon: 'ios-stats-outline' },
  { title: 'Survey', component: SurveyPage, icon: 'ios-analytics-outline' },
  { title: 'ReportIssue', component: ReportIssuePage, icon: 'ios-bug-outline' },
  ];

}

app.html

<ion-content>
  <ion-list>
    <button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
      <ion-icon item-left [name]="p.icon"></ion-icon>
      {{p.title}}
    </button>
  </ion-list>
</ion-content>

I want to show complaint item if complaint status is 'NEW'.

So, Is it possible to showing complaint item for some specific condition? I tried with ngIf but its do not work.

what is the best way to implement this kind of features?

Tusharbalar avatar Dec 25 '16 12:12 Tusharbalar

Why don't you try asking in the support forum?

rapropos avatar Dec 26 '16 21:12 rapropos

Hello! Thanks for opening an issue with us! As this seems like more of a support question i will urge that you ask this question on our forum or on our slack channel. Thanks for using Ionic!

jgw96 avatar Dec 27 '16 15:12 jgw96

Hi Tusharbalar, how did you get this solved. Kind Regards

mainakanyi avatar Jan 10 '17 06:01 mainakanyi

Hello @mainakanyi, I have implemented the same thing, and it's working correctly in my app

.ts file

export class MyApp {

  public status: boolean = false;
  @ViewChild(Nav) nav: Nav;
  constructor(public platform: Platform) {}

  initializeApp() {
    this.platform.ready().then(() => {
      this.networkService.checkNetworkStatus();
      StatusBar.styleDefault();
      Splashscreen.hide();
      this.getStatus();
      if (this.platform.is('ios')) {
        Keyboard.disableScroll(true);
      }
    });
  }

  getStatus(condition here) {
    if (your logic here) {
      this.status = true;
    } else {
      this.status = false;
    }
  }

}

HTML file

<ion-content>
  <ion-list>
    <button *ngFor="let p of pages"  *ngIf="status" menuClose ion-item (click)="openPage(p)">
      <ion-icon item-left [name]="p.icon"></ion-icon>
      {{p.title}}
    </button>
  </ion-list>
</ion-content>

let me know if you are not able to do this thing, i will provide more code

Tusharbalar avatar Jan 11 '17 12:01 Tusharbalar

Working as well. Thanks

mainakanyi avatar Jan 11 '17 12:01 mainakanyi

how do i append pages from another page. means :+1: app.component.ts; page content navmenu variables like pages, but from another page i would like to append value in this.pages

from login.ts append below objects in existing variable which is available in app.component.ts how do i bind and sync this.pages = [ { title: 'Log out', component: logOut, icon: 'logout' }, { title: 'abc', component: xyz, icon: 'ios-ls' }, ];

bhumin3i avatar Feb 23 '17 10:02 bhumin3i

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 03 '18 23:09 ionitron-bot[bot]