I'm creating an app where I have two apps or Divs
. One is bootstrapped using ng-app
directive, while the other one, I'm manually bootstrap using angular.bootstrap
method.
The thing is both these divs
are using a session
service which $broadcasts to $rootScope
, but as you can see when you the $rootScope
is not shared between apps.
So a $rootScope.$broadcast
in appB
is not caught by appA
.
Here is a demo:
angular.module('ngApp', [])
.controller('ngAppController', function($scope, $rootScope) {
$scope.msg = "Waiting for message..";
$scope.$on('YO', function() {
$scope.msg = 'Message recd';
});
//$rootScope.$broadcast('YO');
});
var bElement = document.querySelector('#appB');
angular.module('appB', [])
.run(function($rootScope) {
$rootScope.msg = "Hello from app 'b'";
$rootScope.$broadcast('YO');
});
angular.bootstrap(bElement, ['appB']);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="ngApp" ng-controller="ngAppController">
<div>{{msg}}</div>
</div>
<div id="appB">
<div>{{msg}}</div>
</div>
How can I make it so that I can catch broadcast from appB
into appA
?