Angular scope.$$child undocumented property

by jarnal

HTML

<div ng-app="App">
    <div ng-repeat="num in [1,2,3]" ng-bind="num"></div>
    <div list-numbers></div>
</div>

JavaScript

angular.module('App', []).directive('listNumbers', function($timeout) {
    return function(scope, elem) {
        // timeout to wait for ngRepeat to finish so we can access its scopes
        $timeout(function() {
            var list = [];
            // get $$childHead first and then iterate that scope's $$nextSiblings
            for(var cs = scope.$$childHead; cs; cs = cs.$$nextSibling) {
                list.push(cs.num);
            }
            elem.text("From child scopes: " + list.join(', '));
        });
    };
});