How can we export and use variable that came from subscribe


#1

hello every one :slight_smile: I need to know how can i export and use variable that came from res here (this.allPlaces)

export class Places {
items: string[];
parentId:any;
Title:any;
loader:any;
allPlaces:any;
contnent:any;
countPlaces:any;
allPlacesname:any;
constructor(
public navCtrl: NavController,
public modalCtrl: ModalController,
public navParams: NavParams,
public placesProviders:PlacesProviders
)
{
console.log("/************** places *****************/");
this.loader = true;
navParams.get(“placeName”)?this.Title= navParams.get(“placeName”):this.Title=" ";
navParams.get(“placeId”)?this.parentId={id:navParams.get(“placeId”)}:this.parentId={id:0};
this.placesProviders.getPlaces(this.parentId)
.subscribe((res) => {
if(res)
{
this.allPlaces=res.allPlaces
console.log(this.allPlaces);//data print here :writing_hand:
this.countPlaces= this.allPlaces.length;
this.loader = false;
this.contnent=true;
console.log(“this.allplaces”, this.allPlaces);
}
else
{
this.contnent=false;
this.loader = false;
}
});
console.log(this.allPlaces);//data undefined here :writing_hand:
}
Thanks :slightly_smiling_face: