I'm using tabs in Ionic 2 but I can't pass parameters between them.
Currently what I am trying to do is import the class that contains the tabs into one of the tabs and try to access a method of that class that returns the values.
Tabs.ts
import { Component } from '@angular/core';
import { NavParams, NavController } from 'ionic-angular';
import { ConfigPage } from '../config-page/config-page';
import { IndexPage } from '../index-page/index-page';
import { ProfilePage } from '../profile-page/profile-page';
import { Welcome } from '../welcome/welcome';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
public datosTienda: any;
tab1Root: any = ConfigPage;
tab2Root: any = IndexPage;
tab3Root: any = ProfilePage;
constructor(
private navParams: NavParams,
private navController: NavController
) {}
ngOnInit(){
this.datosTienda = this.navParams.get('datosTienda');
}
getDatos(): any{
if(this.datosTienda != undefined) {
return this.datosTienda;
}
}
}
The Store data comes from welcome.ts, which I pass through the navController.push and I receive it without any problem.
Index-page.ts:
import { Component } from '@angular/core';
import { NavParams } from 'ionic-angular';
import { TabsPage } from '../tabs/tabs';
@Component({
templateUrl: 'index-page.html',
})
export class IndexPage {
public datosTienda: any;
constructor(
public navParams: NavParams,
public tabsIns: TabsPage,
){ }
ngOnInit(){
this.datosTienda = this.tabsIns.getDatos();
console.log(this.datosTienda);
}
}
The error it is giving me is:
Can't resolve all parameters for IndexPage: ([object Object], ?)
Any ideas?
I self-solve the question hehe.
To pass data between tabs we first have to modify the view of our tabs.html
We will add
[rootParams]="parametros"
Later in the controller where we want to receive these parameters. For example the index.ts we will leave it like this:
And ready now in dataTienda we will have the parameters that we have passed from tabs.