B
B
Bogopodoben2016-07-28 08:52:40
Angular
Bogopodoben, 2016-07-28 08:52:40

How to load data into service before Angularjs page loads?

Good afternoon. The essence of the problem is that when a user logs into the personal account, some data such as the user's role is written to a separate service in order to work with them, and so that no one can overwrite this data from outside.
But when the page is reloaded, the service clears all the data stored in it and the check for the role in the run config cannot pass, since it is undefined.
How to be?
Can you still refuse the service, in the direction of something simple and no less safe?
For injecting data in some way before the page is loaded?
upd:
It turns out that the object stores data in itself, but I can’t work with them, because they are not assigned to it, or I don’t understand it that way.
a4949a2f521542d4ada79590368fed78.PNG
Can they be put into an object to reach them? Or is it all heresy?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex, 2016-07-28
@streetflush

How do you know that the user is logged in after reloading the page?
In the place where the check is taking place, you can also fill out the service.

M
Maxim Nagaev, 2016-07-28
@mnagaev

when logging in, write everything to localStorage. It doesn't matter if the page is reloaded. And delete when you exit.

V
Vladimir, 2016-07-28
@Casufi

Read about promises, think over the architecture, taking into account the fact that data can come after the page is rendered, this is angular, here you need to think in angular.
In general, data that does not affect page rendering is best stored either in a service or in a factory, so in this regard the solution is absolutely correct, but when designing a controller, you need to take into account that the service can receive some data after the first rendering of the page, for example, the back gives data with a delay .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question