I am new to Ionic2 and I don't really understand how asynchronous programming works.
I want function checkLogin() to return the value of 0 or 1, however, instead it returns the result below. How do I make the variable this.isLoggedInto be assigned the value I desire?
Any advice or suggestion would be appreciated.
Thank you in advance.
Provider
checkLogin() {
var url = this.app.URL + 'api/program/information';
var isLoggedIn;
return this.http.get(url).map(res =>res.json()).subscribe( logininfo =>{
if (!logininfo.data.information.is_logged_in) {
isLoggedIn = 0;
} else {
isLoggedIn = 1;
}
return isLoggedIn;
})
}
home.ts
ionViewWillEnter() {
this.isLoggedIn = this.globalVar.checkLogin();
console.log(this.isLoggedIn);
}
