I've been browsing for solutions to a problem and stumbled upon an answer provided by Mark Rajcok
angular JS - communicate between non-dependend services
However, I am struggling to fully grasp his explanation, particularly this part:
angular.forEach(event1ServiceHandlers, function(handler) {
handler(some_data);
});
I'm uncertain if the event1ServiceHandlers array is filled with functions (referred to as handler) that are executed within this forEach loop.
It would be immensely helpful if someone could provide a clear example of setting up a publish/subscribe system.
I have two services that need to communicate with each other, but I want to steer away from using $rootScope.$broadcast. After researching, it seems like implementing a pub/sub service is the optimal approach. One of my services must call a function within the other service. However, due to one service being a dependency of the other, I cannot establish a mutual connection because of circular dependencies.
Therefore, my question is: If you have two AngularJS services (factories), how can service 1 trigger a function in service 2 when service 2 already depends on service 1? This should be done without utilizing $broadcast and $on.