In my App i need to check, if a user is allready in the local storage, befor i call my api. if the user is allready in the storage, i want to give back the old data and dont call the api again.
My problem is, that when i try to check the sotrage, my app calls the api to fast. I dondt understand why.
So i call my getUser methode, in this method i check the localstorage value and then i check the value.
Maybe there is a way to tait for the local storage data.
And on the receiving side (if it is split up in multiple functions): class.callApi().then(result => { /process/}).catch(no_result => {/* fetch*/});
You could also just call the function to fetch the user here in callApi() and resolve with new fetched data. (instead of rejecting it and handling it elsewhere.)
I can see the problem. The http uses Observable. This is executed asyncronously.
You should use callback functions in your loadProfile, I suppose… or wait!
Maybe try this using ‘toPromise()’ and modified your code to return promise: