eya eya - 1 year ago 317
TypeScript Question

ionic 2 - calling pages functions from app.component.ts

I have an ionic 2 appliction containing a menu and every time I select one item from the menu the main page should be updated, for that I wrote a function in my

that returns the wanted result as a list , and in
I have to call that function to be executed ..

What should I do please ??

Thanks !

Answer Source

Do I unsderstand your question correctly, how can you fire your function in main.ts from app.components.ts?

You could use Ionic2 Events for this purpose:

In app.components.ts:

import { Events } from 'ionic-angular';
constructor(public events: Events) {

clickMenu(item) {
events.publish('menu:clicked', item);

Add clickMenu(item) to your menu-item: (click)="clickMenu('whateverYouWantToPass')"

and in main.ts:

import { Events } from 'ionic-angular';

constructor(public events: Events) {
events.subscribe('menu:clicked', (item) => {
  // Do something with the clicked item data, e.g.:

I hope this brings you closer to your solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download