S
S
SheldonCoop2016-04-18 10:35:02
JavaScript
SheldonCoop, 2016-04-18 10:35:02

How to restart a factory in AngularJS?

There is an application on Angular, I met such a problem when we log in for a user on the login page, we are transferred to the main page, where there is some data for the current user. The data is pulled using a factory get request, as follows - $resource('api/users/'+token+'/resources'), if you return to the login page and log in as a different user, then the data from the previous user remains on the main page, until the page is refreshed. As I understand it, this is due to the fact that the factory creates an object when the application starts, and then returns it every time. How can this be fixed so that when you log in as another user, you can get a new object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-04-18
Protko @Fesor

The data is pulled with a factory get request,

So, let's do it again.... What is a factory? Now who is doing the get request anyway? Seriously.
When you log out, you should have cleared the old state and not tried to re-create the service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question