Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I would like to know if there is a way to access the $scopes variables using the $rootScope such that if a function is defined in scope I can invoke it using $rootscope to or if there is a variable defined using $scope.var1 I could access it using $rootScope to

share|improve this question
    
$scope is child of $rootScope simply they maintain inheritance relation between them..and you know parent can not have access to its child...as child can access its parent info..because its generalize.. – Pankaj Parkar Sep 9 '15 at 16:12
    
@PankajParkar Actually parent has access to its child scope. So it is possible, however not very useful. – dfsq Sep 9 '15 at 16:14
    
@dfsq Thanks. curious to know how can we do that..? – Pankaj Parkar Sep 9 '15 at 16:15
3  
"Sure, I can show you how to drive your car off the road real fast & nice!" – Mikko Viitala Sep 9 '15 at 16:23
1  
There's no reason for $rootScope to access his childscopes. You should really try to avoid this. – Leo Sep 9 '15 at 16:25
up vote 4 down vote accepted

Every scope have a two property references to its child scopes, namely: $$childHead and $$childTail. Additionally every scope object has $$nextSibling and $$prevSibling properties pointing to same-level scope sibling instances. Having this properties you can travers all child scopes horizontally or vertically. Depending why you need to do it on each step you would check for necessary scope property or method.

That being said, I can't see real business-logic application for such child scope traversal, except for logging/debugging purposes, for example to build scope hierarchy tree, etc.

share|improve this answer
    
I have tried to access the child scope but I'm not able to that – Gardezi Sep 9 '15 at 16:35
    
I did it like this $rootScope.$$childHead but I get null in return – Gardezi Sep 9 '15 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.