Ionic 2 Root Controller question

I expect this is easy but I am not sure what the best way of doing it is.

I have a tabbed application and a main component that displays information by date.

On tab 1 I want to display today’s data and on tab 2 I want to display tomorrow’s data.

Rather than have two components, one for Today and one for Tomorrow like this:


  <ion-tab tab-title="Today" tab-icon="clock" [root]="TodayRoot"></ion-tab>
  <ion-tab tab-title="Tomorrow" tab-icon="fastforward" [root]="TomorrowRoot"></ion-tab>


export class TabsPage {
  constructor() {
  this.TodayRoot = TodayPage;
  this.TomorrowRoot = TomorrowPage;

how could I have ONE component called DataPage and pass a parameter to it from tabs.js (i.e a parameter of “Today” or “Tomorow”) ?

1 Like

Maybe you can get some idea from this article:

so you can reference your parent in your component or simply use events :smile:

Hope that helps.

Load the parent with @Parent --> and call functions and retrieve data of the parent via that component.
But i do not like that approach (in angularjs 1.x i do not like it, too :slight_smile: )

For events you can use the EventEmitter:

if you want to implement something like a “service” or “factory” --> create a simple js-file --> and export your getters and setters as a class or simply as a function-collection

1 Like

thanks, I’ll take a look