3

I decided it's time for me to explore the hidden side of testing directives, and now when I do something with a directive that has an isolated scope:

parentScope = $rootScope.$new()
parentScope.dasDingy = "bla bla dingy"
element = angular.element("<foo dingy='dasDingy'></foo>")
$compile(element)(parentScope)
$rootScope.$digest()

scope = angular.element(element).scope()
console.log(scope.dingy) //  is undefined --- Nah, ain't exist
//  but, if I do
console.log(scope.$$childHead.dingy) // it exists and it's == 'bla bla dingy'

So, what the heck is scope.$$childHead and why it is not accessible directly on scope? or maybe I'm doing something stupid here?

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
iLemming
  • 34,477
  • 60
  • 195
  • 309

1 Answers1

7

In this case scope.$$childHead is the isolated scope of the <foo> directive. See here in the source code where and when this.$$childHead is assigned. See the console output in this plnkr for examples using directives with diferent types of scope (shared, isolated, new).

Sylvain
  • 19,099
  • 23
  • 96
  • 145
  • 1
    Is there a reason why you can't use (in the above example) element.isolateScope() instead of accessing $$childHead directly? – Steven Rogers Jun 28 '16 at 21:00
  • 1
    @StevenRogers I think using `element.isolateScope()` is preferable; In the following example, `$$childHead` may not target the expected element: http://jsfiddle.net/3agvyp8t/2/ – Eric Norcross Nov 23 '16 at 02:31