When I'm logging the value of my variable inside the subscribe i have a value but when doing it outside it i get undefined ???:
this._postService.getConf("app/conf/conf.json")
.subscribe(res =>{
this.home = JSON.stringify(res);
console.log("value :" + this.home);
i want to initialize my home variable with a certain value I'm doing it on ngOnInit but it get the value undefined when I'm trying to get it outside:
This is my function :
getConf(url) {
return this._http.get(url).
map(res => {return res.json()});
}
ngOnInit() {
this._postService.getConf("app/conf/conf.json")
.subscribe(res => {
this.home = JSON.stringify(res);
console.log("hahowaaaaaaaa" + this.home);
}
);
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));
}