Hello there. I am currently working on displaying my user's information in the sidemenu, and after some research, I found that using the Events class might solve this issue. However, I have noticed that the data saved in subscribe gets destroyed whenever I refresh the page or close the application. How can I ensure that the data persists even after the application is closed or when I refresh the browser? All imports are functioning correctly, but it seems like saving the data is the main problem here.
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any;
profileName: string;
profileEmail: string;
user: any;
pages: Array<{title: string, component: any}>;
constructor(public events: Events, public platform: Platform,
public statusBar: StatusBar, public splashScreen: SplashScreen) {
this.initializeApp();
if(localStorage.getItem('loggedIn')==='1')
{
this.events.subscribe('user', (user)=>{
this.profileName = user.firstname + ' ' + user.lastname,
this.profileEmail = user.email
console.log(user);
});
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'Messages', component: ChatlistPage }
];
this.rootPage = HomePage; //HomePage
}
else{
this.rootPage = LoginPage;
}
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
logoutUser() {
localStorage.clear();
window.localStorage.clear();
this.nav.setRoot(LoginPage);
}
}