In my service I'm trying to get data from my backend, when I click on the button for the first try it returns undefined, but on the second try everything works fine, someone have any suggestions that would fix this for me.
my provider function is below:
getArtisants(){
this.HttpClient.get('http://localhost/AlloMealem/backend/web/index.php?r=artisant/all').
subscribe(result => {
this.artisans=result;
});
return this.artisans;
}
My service function that gets the data from the provider and put it in an array so I can use it in my components
getArtisants() {
this._artisans=this.searchProvider.getArtisants();
}
}
I expect to get my data in the first try because some of my pages should get data in the onInit() function which makes it important to get data in the first try.