I
I
Isherath2018-09-08 21:57:26
Angular
Isherath, 2018-09-08 21:57:26

Order of execution of factory methods in AngularJS?

I have a factory, let there be two methods. The first one makes a request to the server and returns data about the user. After that, they are stored there until the page is completely reloaded. Such a data warehouse. The second method simply returns this data from the store.
There is a controller in which, if the page is reloaded and the storage is cleared, then the first factory method loads this data again into the storage, and the second returns it to the controller. Further, this data is displayed in inputs using ng-model.
And there is a problem. When you just navigate through the pages, then all the data is displayed as it should, once loaded from the server and displayed in its place. But it is worth reloading the page and immediately everything disappears. Judging by the console, the first method loads everything normally when reloading, but the second one does not return anything, because it works first, that is, before the first method loads the data ... naturally, there is nothing to return. I understand that these two methods work synchronously and the problem is in the time of the first method, tk. it runs longer due to the call to the server.
How to overcome it. How to make everything work in order? first the first one will load everything needed, and then the second one will display everything needed? How to make this asynchronous?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question