When I call the GetAllMainStore() function, data is successfully retrieved from the API and the console indicates that "this.MainStoreArray" contains data.
The problem arises when I attempt to access "this.MainStoreArray" outside of the GetAllMainStore() function - the array appears empty. I am struggling to understand why this is happening as the console.log in the ngOnInit function shows an empty result.
ngOnInit() {
this.CurrentStore = this.stateService.CurrentStore;
this.CurrentMainStore = this.stateService.CurrentMainStore;
this.stateService.CurrentStore = undefined;
this.stateService.CurrentMainStore = undefined;
this.GetAllMainStore();
console.log(this.MainStoreArray);
// this.EditStoreForm = this.formBuilder.group({
// storeId: [this.CurrentStore.storeId],
// storeName: [this.CurrentStore.storeName, Validators.required],
// storeLocation: [this.CurrentStore.storeLocation],
// storeRating: [this.CurrentStore.storeRating]
// });
}//ngOnInit
GetAllMainStore() {
this.dataService.GetAllMainStores().subscribe((data) => {
this.MainStoreArray = data;
console.log(this.MainStoreArray);
});
}// get Main Store