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']))
}
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.
yes you right your approach very logical I will try it, but I Have a question if we subscribe data in service, how can I call inside pages like example up @Jonathan
Could you add more information, like the scenarios or when do you want to request the service? I don't understand your question
I mean i want to subscribe the data inside service and call in home page,in my exemple I'm subscribe the data in home page,I'm usually use .then() but in this exemple it's impossible @Jonathan Lopez
You could transform your observable into a Promise with a pipe, but I remmend you to use observables in Angular. But I don't really understand why you want to this inside your service, I mean also you have to use the information in your component and you have to call your service independent it's a promise or observable
alright, thanks for your time @Jonathan Lopez