@riyad786 wrote:
Hi,
I am a newbie of IONIC. I have one simple problem that I could not use promise value for my typescript class. It is returning the object but I need the value. Otherwise one of my conditions doesn’t fulfill. Can anyone guide me how can be used this promise value into typescript class? Code is
app.component.ts
import { TabsPage } from '../pages/tabs/tabs'; import {SocialActivitiesPage} from '../pages/social-activities/social-activities'; import { HomeTabsPage } from '../pages/home-tabs/home-tabs'; export class MyApp implements OnInit { rootPage:any = TabsPage; socialProfile:any = SocialActivitiesPage; hometabs:any = HomeTabsPage; @ViewChild('nav') nav:NavController; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public menuCtr:MenuController, private storage: Storage,) { } token:Promise<any> = this.storage.get('token').then((val)=>{ return this.token = val; }).catch( (err)=>{ console.log(err); } ) ngOnInit(){ if(this.token!==null){ this.rootPage = HomeTabsPage; } } ionViewDidLoad(){ console.log(this.token); } }
Above code is my app.component.ts where I resolved my token promise by below this
token:Promise<any> = this.storage.get('token').then((val)=>{ return this.token = val; }).catch( (err)=>{ console.log(err); } )
And tried to make one condition into ngOnInit()
ngOnInit(){ if(this.token!==null){ this.rootPage = HomeTabsPage; } }
unfortunately here this condition is not working. Whether my token is null or not null. Here this.token is one object, not any value. But If I call this token from app.html it returns as a string value, not an object. I tried to call this token into app.html like this way
{{token}}
It is showing the string value. Unfortunately, from the typeScript class, it is always showing my one object that has some
_zoneSymboleType
and_zoneSymboleValue
. Here in_zoneSymboleValue
I can see my value. So my question How can I use this.token as a value, not as an object into my typeScript conditions.
It would be highly appreciated your effort.
Thanks
Posts: 1
Participants: 1