When I hard-code the variable (this.username) things work just fine, but using the storage-value doesn’t work.
I know there’t time needed to retrieve the data, but I don’t know how to return the function-return-value within the promise.
Lot’s of things I tried (like returning a new Promise etc.) for hours and hours, but can’t get it to work, so hope someone can help.
You should probably have a loot at some tutorials about asynchronous code, promises and Observables. Maybe first you could have a look to the following tutorial:
I get the basics of asynchronous code/Promises and Observables, but the problem here I quess is that ‘getSectionData’ needs a return value which can’t be returned within the Promise …
The “basics of asynchronous” is not correctly implemented in your piece of code that’s why I suggested to have a look to the tutorial respectively username will always be not defined in your get or luckily will be set. I will suggest to firstly fix that
I have read the tutorial and now understand that the Promise has a local scope. But how do I now get the variable from that scope in the url?
Placing the return in there doesn’t work, but I really do not know how to get the variables out of there in de url-construction and return the http-get-data
Ok so I gonna try to summarize really quick: if you have promises in a function/method, just forget “return a value”, it ain’t gonna work most of the time
what you could do is “return a promise”
I just gonna transform ugly quick and dirty your code
Thank you so much, got it working now!
Beginning something new can be so hard
On the other hand, the same code that’s working now, didn’t work at first … than I changed something (because of an error), I received another error, changed it back, and then suddenly it worked without errors …
Fun it was this morning, but now I run into troubles catching errors (401).
In the getData-function I implemented a loadingcontroller. It shows when loading, and dismisses after a successful load, but when I receive an error (ea 401), I don’t know how to pass this error, just like the data, to the getData-function. Only “error here #1?” is shown, while I expected to see “error here #3?” or “error here #4?” so I can dismiss the loadingcontroller and display a message.