Get to get all child scopes in Angularjs given the parent scope

ritcoder picture ritcoder · Sep 29, 2012 · Viewed 42.2k times · Source

I would like to know how to get a list of all child scopes given a parent scope. All I can find from the properties of the scope are $$childHead, $$childTail, $$nextSibling and $$prevSibling.

The approach I'm using now is to get the childHead from the parent and then using the nextSibling to get the next child until nextSibling is null.

Is there a better approach? Given that I want to call a method [getModel] on all the children, is there again a better way of doing this?

Answer

Azri Jamil picture Azri Jamil · Nov 18, 2012

All Angular scope are attached to DOM element, you can start by inspecting child using the current element down to whatever child you want to reach. Once there, use below function to get the scope.

angular.element('#5th_element').scope();