Hello,
I have been practising Ionic 4 for a few days and I have a problem that I can’t solve on my own. Basically I have a tabs app (created with ionic start tabs). I also have a service and in my app and a function in it that returns a string. In my tab controller I declare a new variable and call the service function to assign its return value to the variable. However, this string does not automatically update in the view if it changes. I have tried reassigning the value to it inside ionViewWillEnter but this only gets called when the tab is loaded for the first time. Any ideas how I should address this?
export class Tab3Page {
constructor (public storage: Storage, public router: Router, public platform: Platform, public ds: DataService) {}
public loggedUser: any = this.ds.getLoggedUser();
ionViewWillEnter() {
this.refresh();
}
refresh() {
let loggedUser = this.ds.getLoggedUser();
console.log("Logged user: ", loggedUser);
this.loggedUser = loggedUser;
}
logout () {
//logout stuff
}
}
In my view I use to display logged user’s username like:
{{ loggedUser.username }}
Thanks.