question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically add items to Ionic 2 side menu

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
mainakanyicommented, Jan 10, 2017

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

1reaction
Tusharbalarcommented, Jan 11, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change side menu items dynamically in Ionic 5 - Stack Overflow
Create event service. In the EventService.ts: export class EventService { private dataObserved = new BehaviorSubject<any>(''); currentEvent ...
Read more >
Add Dynamic Side Menu in Ionic 6 App with Active Class
A comprehensive Ionic step by step tutorial, Learn how to implement side menu dynamically in Ionic app with active class for selected page....
Read more >
Dynamically add items to Ionic 2 side menu #9791 - GitHub
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...
Read more >
How to dynamically show an ion-menu in Ionic 4 - Jordan Benge
First things first. Generate a new component called side-menu by using ionic g component components/side-menu This is going to house our ion ......
Read more >
Dynamically Adding ion-menu in app.component.html
I am just getting started with ionic-4 and wanted to know how could I generate the code needed for ion-menu and insert it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found