Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 769
Gardezi Avatar asked Sep 26 '22 19:09

Gardezi


1 Answers

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.

like image 145
dfsq Avatar answered Sep 30 '22 08:09

dfsq