In my map.service I have coded like this
loadAdminDataDiv (): Observable {
return this.http.get(\"static/data/data.json\")
Here I got another way... I used static keyword for solving this problem...
getSubscribeData: any;
getAllvaluesFromFiles() {
this._mapService.loadAdminDataDiv().subscribe(data => {
this.getSubscribeData = data;
YOUR_CLASSNAME.setSubscribeData(data);
},
error => { console.log(error) },
() => {
console.log(this.getSubscribeData); // prints the data
}
);
}
ngAfterContentInit() {
this.getAllvaluesFromFiles();
console.log(this.getSubscribeData); // prints Undefined
console.log(YOUR_CLASSNAME.subscribeData); // prints
}
static subscribeData:any;
static setSubscribeData(data){
YOUR_CLASSNAME.subscribeData=data;
}
try to use this ... hope this will help you