The class variable counties, doesn't hold on to the value assigned within the subscribe method on fetchCounties(). Logging the temp variable data returns a good list of counties, so does this.counties INSIDE of the subscribe, but as soon as I try access it outside of the subscribe it becomes undefined. Coming from a Java background and being new to Angular/Typescript this makes no sense to me...
public counties: ICounty[] = [];
public getCounties(): ICounty[] {
this.fetchCounties().subscribe(data =>{
console.log("data");
console.log(data);//logs correctly
this.counties = data;
console.log("counties inside subscribe " );
console.log(this.counties);//logs correctly
});
console.log("counties outside of subscribe " );
console.log(this.counties);//logs incorrectly (empty) >:0
return this.removeInvalidCounties(this.counties); //passes empty counties list...
}