I am finding it very difficult to find the root cause of a particular issue in my code. The source code is here
I want to access $rootScope
, but one of the way is failing.
Route 1:
Get the first element in DOM with ng-scope
class and do a angular.element(elem).scope().$root
to get the root.
Route 2:
Get the first element in DOM with ng-scope
class and get the injector on the element by angular.element(elem).injector()
and by doing a injector().get('$rootScope')
I can get the $rootScope
.
In Route 1 when my code does, angular.element(document.querySelector('.ng-scope')).scope()
I get undefined because scope
is not available on this element. I tried to get the angular.element(elem).data()
, but I get an empty object.
Does this mean that angular has not yet run through this element ? If yes, why do I see an ng-scope
class already being applied if angular has not yet gone through this element ?
What is the difference between accessing $rootScope
through injector().get('$rootScope')
and through scope().$root
? Why does my Route 1 fail ?
Route 1:
Route 2: