angularjsangular-ui-routerangularjs-rootscope

access $scope from $rootscope angularjs


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


Solution

  • 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.