Hi,
I am using local storage in my application, which works very well on the first time and on the second time it show empty otherwise it is show previous username.
Below is the code .
First page for setting data
Login.ts
if(this.responseData.result==‘true’){
localStorage.setItem(‘username’,this.userData.loginname )
this.navCtrl.push(TabsPage);
}
app_component.ts
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen,
public menu : MenuController ) {
this.initializeApp();
// used for an example of ngFor and navigation
this.pages = [
{ title: localStorage.getItem('username') ,component: TabsPage,icon:'ios-contact-outline' },
{ title: 'Order-id :', component:SummaryPage,icon:'ios-cart-outline' },
{ title: 'Home', component: TabsPage,icon:'ios-home-outline' },
{ title: 'Help', component: TabsPage,icon:'ios-help-circle-outline' },
{ title: 'Logout', component: null,icon:'ios-exit-outline' }
];
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn’t want the back button to show in this scenario
if(page.component) {
this.nav.setRoot(page.component);
} else {
this.nav.setRoot(LoginPage);
this.menu.enable(false, 'myMenu');
localStorage.clear();
}
}