I have two separate graphical interfaces that are part of the same system. One at the top of the screen (navEditor) and one on the side (routeEditor).
They need two updates each other often and call each other's functions.
Each has a service that contains most of these system functions. I ran into a problem when I tried to call functions from A-> B and B-> A. This, of course, created a circular dependency, because I had to include them in each other in order to gain access.
I reviewed several solutions, including using $ rootScope. $ broadcast. However, one general suggestion (found here: angular JS - communication between services without dependencies ) suggested a subscriber / publisher method that connected the two together.
This avoids cyclic dependency by using a third service and adding events and handlers of other services to it.
I took this step further and simply asked this parent service to return an object with a place holder object for each of my two systems:
myApp.service('$trafficSys', function(){
this.sys = {
navEditor: {},
routeEditor: {}
}
});
myApp.service('$routeEditor', ['$trafficSys',function($trafficSys) {
var routeSystem = {
}
$trafficSys.sys.routeEditor = routeSystem;
}]);
Then I just used my services "navEditor" and "routeEditor", including $ trafficSys, and then applied all its functions to the navEditor or routeEditor objects.
What I would like to know is that it is considered an Anti-Pattern, and if I am more imperative, not declarative.
. angular, . , , , - .
.