i have a angular module that i bootstrap manually.i am trying to get its $rootScope
to attach a event listener for $viewContentLoaded
.
here is my code :
angular.bootstrap(el, [appname]);
//////////////////////////// Fixing links
console.log('patching');
var $rootScope = angular.injector([appname]).get('$rootScope');
console.log($rootScope);// Scope { $id=139, $root=Scope, $$destroyed=false, more...}
$rootScope.$on('$viewContentLoaded', function () {
console.log('$viewContentLoaded');
});
I am getting a scope $id=139
and the event is not firing when it should.
If i try to get the $rootScope
inside my modules main controlelr i get :
console.log('myController',$rootScope);
Scope { $id=120, $$childTail=Scope, $$childHead=Scope, more...}
I get a $rootScope
with id 120???
and If i attach the event to the controller inside the module the event handler works as it should.
So what am i doing wrong?
How can i get the correct rootScope
of a module outside of its controller?
I should mention that i have a multiple app environment. I have a main module that load and bootstraps other modules and i am trying to know when this other modules viewContent has finished loading with out adding the code to every each one of the manually....
Note:
I can get the $rootScope
like this :
var $rootScope = angular.element(el).scope().$root;
But this doesn't work when $compileProvider.debugInfoEnabled(false);
:(