typescript - Subscribe Observable value -


when i'm logging value of variable inside subscribe have value when doing outside undefined ???:

this._postservice.getconf("app/conf/conf.json")    .subscribe(res =>{       this.home = json.stringify(res);       console.log("value :" + this.home); 

i want initialise home varibale value i'm doing on ngoninit value undefined when i'm trying outside:

this fonction :

getconf(url){    return this._http.get(url).       map(res => {return res.json()});  } 

//ngoninit :

ngoninit(){          this._postservice.getconf("app/conf/conf.json")    .subscribe(res =>{        this.home = json.stringify(res);       console.log("hahowaaaaaaaa" + this.home);  }   );        //// acount     this._postservice.getposts(this.home)     .subscribe(result =>{        this.loading = false;       this.actionsg = result;        var count = json.stringify(result);        this.acount = count.substring(count.indexof(','),23);      },error=> console.error('error: ' + error), ()=> console.log('finish! actionsg'));  ////   this._postservice.getposts(this.home ).subscribe(result => this.actionsv =      result, error=> console.error('error: ' + error), ()=> console.log('finish! actionsv ngoninit' + this.page));      } } 

that's how observables work. when response server arrives, callback passed subscribe(...) called observable.

the console.log() outside of subscribe() executed before call server made.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -