I have fallowing setup for my project:
- mainApp main angular module, containing EventBus factory
- app1 first module with mainApp injected
- app2 second module with mainApp injected
app1 and app2 are two modules placed on the same page, both have mainApp injected.
I am trying to communicate between app1 and app2 using EventBus factory, which is defined in mainApp. Unfortunately, I can't get it to work (app1 doesn't catch app2 event, and opposite).
How should I resolve that? Have I take a wrong approach?
EventBus.subscribe("App1Ctr.event", function (event, data) {
console.log("App2handler");
$scope.name = data.newVal;
});
$scope.fireEvent = function () {
EventBus.broadcast("App2Ctr.event", {"newVal": "App2Ctr"});
};
Here is a plnkr