Issue
I m trying to use variable after the subscribe block,but I can't look at snippet:
async check(){
this.VersionNumber = await this.appVersion.getVersionNumber()
this.settingsService.getjson().subscribe(item=>{
this.djson = item
alert(this.djson) /// here work
});
alert(this.djson) /// here not work, I got : [object:Object]
if((this.VersionNumber !== this.djson) ){
this.presentAlertConfirm();
}
}
settings.service.ts
getjson(){
return this.http.get('./assets/jsonfile.json').pipe(map(res=> res['currentVers']))
}
Solution
Subscriptions are asynchronous that is why you get that error, you could create a function to have to logic to validate the data and call this function inside of the subscribe to have the value set when you want to use it.
Answered By - Jonathan Lopez
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.