Call 2nd Angularjs controller after the competition 1

I am new to AngularJs. I have a situation where I need to get the same data for several controllers. So, I found out that I use the angularJs service for this, and I call this service on the controller.

Now, when I call this service from both controllers, the service receives twice. I cached the data in the service, but still the service generates two ajax requests to the server.

How to cope with this situation?

+4
source share
2 answers

Every time you call a service method, no matter where you call it from, it will be launched. Therefore, if you have two controllers and you call the service method from each controller separately, the service method will be executed twice.

0
source

I cached the data in the service, but still the service generates two ajax requests to the server.

, $http , :

SO, , , : 1 $http 2 , .

broadcast, , ( $http). , . GL!

0

Source: https://habr.com/ru/post/1589268/


All Articles