加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 仅适用于新的范围?

发布时间:2020-12-17 08:06:06 所属栏目:安全 来源:网络整理
导读:这可能听起来有点笨拙..但是如果只有在创建新的范围时插入“ng-scope”类,或者是否有其他东西,我有问题的理解? 示例:我将这些代码行链接到控制器: button class="btn" ng-click="open()"Open me!/buttondiv ng-show="selected"Selection from a modal:
这可能听起来有点笨拙..但是如果只有在创建新的范围时插入“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:

Notice 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读