什么是范围。$$ childHead?

时间:2014-07-03 02:51:02

标签: javascript angularjs unit-testing coffeescript

我决定是时候探索测试指令的隐藏方面,现在当我对具有隔离范围的指令执行某些操作时:

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'

那么,问题是scope.$$childHead以及为什么不能直接在范围内访问它? 或者我在这里做些蠢事?

1 个答案:

答案 0 :(得分:7)

在这种情况下,scope.$$childHead<foo>指令的孤立范围。请参阅here in the source code分配this.$$childHead的位置和时间。有关使用具有不同类型范围(共享,隔离,新)的指令的示例,请参阅this plnkr中的控制台输出。

相关问题