Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么transclude创建父对象的子范围?_Javascript_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript 为什么transclude创建父对象的子范围?

Javascript 为什么transclude创建父对象的子范围?,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我想知道,为什么指令的转置内容绑定到外部范围的子范围,而不是外部范围本身,我找不到答案 我不是说隔离作用域或使用scope:true创建的作用域 在我看来,使用外部作用域会更直观,因此在其上设置基本属性将如预期的那样工作,我知道“点”等,但是,为什么不保持简单呢 <div ng-controller="Parent" ng-init="count=0"> Current count: {{count}} <directive-with-transclude>

我想知道,为什么指令的转置内容绑定到外部范围的子范围,而不是外部范围本身,我找不到答案

我不是说隔离作用域或使用scope:true创建的作用域

在我看来,使用外部作用域会更直观,因此在其上设置基本属性将如预期的那样工作,我知道“点”等,但是,为什么不保持简单呢

<div ng-controller="Parent" ng-init="count=0">
   Current count: {{count}}
   <directive-with-transclude>
       <!-- won't work because the count is set in a child scope of Parent's scope -->
       <a href ng-click="count++">Increment</a>
   </directive-with-transclude>
</div>

这个决定有什么原因吗?

$parent.count这个有效吗?是的,它可以以各种方式工作,我只是想知道为什么Angular决定以这种方式工作,而不是以两种方式工作。我的问题是:。你能设置plunk以便我们可以围绕它玩吗,弄清楚我的问题是理论上的,我不认为一个劫掠者会有多大用处