I am trying to make an ionic tab dynamic. I have 5 tabs on my app. The last tab need to change base on the users previous page that he/she was on
Here is a picture of it, So as you can there are 5 tabs(the last one is a location icon). I need the last one to change based on the users page history.
My thinking is to store the page history in locastorage and call it everytime the page changes, though I am not sure how to go about this
How much Angular do you know? The “simplest” solution is to create a provider. That provider’s job is to emit the current value of the icon. Your tabs page listens to that. In Angular, you can use a BehaviorSubject. That’s best. Look it up and see if you can figure it out. It takes some getting used to.
If you don’t like that, another solution is to use Ionic Events Your tabs page subscribes to the ‘changeIcon’ event, and you publish an event whenever the icon changes.
this causes an error at “this.tab5Root = SettingsPage;”
[ts]
Type ‘typeof SettingsPage’ is not assignable to type ‘typeof WhereToBuyPage’.
Type ‘SettingsPage’ is not assignable to type ‘WhereToBuyPage’.
Property ‘gotoProductLocator’ is missing in type ‘SettingsPage’.
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { HomePage } from '../home/home';
import { ProductSelectionPage } from '../products/product-selection/product-selection';
import { SettingsPage } from '../settings/settings';
import { ProjectCentrePage } from '../project-centre/project-centre';
import { WhereToBuyPage } from '../where-to-buy/where-to-buy/where-to-buy';
@Component({
selector: 'page-tabs',
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root = HomePage;
tab2Root = ProductSelectionPage;
tab3Root = SettingsPage;
tab4Root = ProjectCentrePage;
tab5Root = WhereToBuyPage;
public rootPage: any = HomePage;
constructor(public navCtrl: NavController) {
}
ionViewDidLoad() {
if (this.navCtrl.getActive().component === SettingsPage) {
this.tab5Root = SettingsPage;
}
else {
console.log('Tab stays');
}
}
}
I tried not assigning tab5Root = WhereToBuyPage but still gives the error
the problem seems to be setting the last tab to a new value, I have tried updating the tab icon via a provide but there seems to be an issue when updating the tab to a new value once it’s initialised at app startup
Ive tried some things out the problem is that the tabs page only loads once and then won’t refresh anymore and you can’t acces the properties from a different page.
Id say go for @AaronSterling answer and create a provider.