这可能听起来有点笨拙..但是如果只有在创建新的范围时插入“ng-scope”类,或者是否有其他东西,我有问题的理解?
<button class="btn" ng-click="open()">Open me!</button> <div ng-show="selected">Selection from a modal: {{ selected }}</div>
在Web控制台中,两者都具有ng范围:
<button class="btn ng-scope" ng-click="open()">Open me!</button> <div ng-show="selected" class="ng-scope ng-binding ng-hide">Selection from a modal: </div>
即使没有角度特定的数据,像这里一样,它将添加一个ng范围:
<div>hello</div>
<div class="ng-scope">hello</div>
但为什么 ??
任何地方都附有一个范围。从
the documentation:
原文链接:https://www.f2er.com/angularjs/144124.htmlNotice that Angular automatically places ng-scope class on elements
where scopes are attached. The definition in this example
highlights in red the new scope locations. The child scopes are
necessary because the repeater evaluates {{name}} expression,but
depending on which scope the expression is evaluated it produces
different result.
而在this answer年,@MarkRajcok表示有角度使用这些来追踪范围(和垃圾收集)。
编辑:
并回答您编辑的问题。不,这不会添加ng范围类:
<div>hello</div>
Here is a plunker看到这个在行动。
请注意,ng-scope类仅适用于声明ng-controller的节点。
<div ng-controller="Ctrl" class="ng-scope"> <div>hello2</div> </div>