是否删除DOM元素删除相关的范围是什么? [英] Does removing a DOM element remove the associated scope?

查看:117
本文介绍了是否删除DOM元素删除相关的范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角,范围与DOM元素相关联。如果你调用 $ element.remove(),确实 $ element.scope()$的destroy()结束获取调用呢?或者是开发商负责清理范围本人呢?

这让我觉得,它删除DOM元素应自动删除该范围:

angular.js

  ////////////////////////////////////// ///////
// jQuery的突变补丁
//
//与bindJQuery拦截所有结合jQuery的DOM API的破坏,并触发一个
// $所有DOM节点上破坏事件被删除。
//
/////////////////////////////////////////////函数JQLitePatchJQueryRemove(姓名,dispatchThis){/ * ... * /}


解决方案

编辑:

角1.2.X现在<一个href=\"https://github.com/angular/angular.js/blob/933537860247de35c21db060ae9ae1f87bb30d53/src/jqLite.js#L166\"相对=nofollow>补丁jQuery来调用$摧毁

不过,我还没有测试,看看我得到了我以前看到同样的结果。

(感谢@KumarHarsh在评论指出这一点)


旧的答案(角1.0.X):

没有, $ element.remove(),因为范围仍然被其他范围内引用不​​排除范围,presumably。

为了证明你可以从一个嵌套的控制器中删除一个范围的元素,然后从父控制器加载范围和检查 $$ childHead 来看看孩子范围内仍然存在。

这里是展示一个普拉克

此外,您还可以在内存使用 Batarang插件Chrome浏览器

In Angular, scopes are associated with DOM elements. If you call $element.remove(), does $element.scope().$destroy() end up getting called as well? Or is the developer responsible for cleaning up scopes himself?

This makes me think that it removing a DOM element should automatically remove the scope:

angular.js

/////////////////////////////////////////////
// jQuery mutation patch
//
//  In conjunction with bindJQuery intercepts all jQuery's DOM destruction apis and fires a
// $destroy event on all DOM nodes being removed.
//
/////////////////////////////////////////////

function JQLitePatchJQueryRemove(name, dispatchThis) { /* ... */ }

解决方案

EDIT:

Angular 1.2.X now patches JQuery to call $destroy

However, I haven't tested to see if I got the same results I saw before.

(Thanks @KumarHarsh for pointing this out in the comments)


Old answer (Angular 1.0.X):

No, $element.remove() doesn't remove the scope, presumably because the scope is still referenced by other scopes.

As proof you can remove a scoped element from a nested controller, then load the scope from the parent controller and check $$childHead to see the child scope still exists.

Here is a plunk to demonstrate

Also, you can view the scopes in memory using the Batarang plugin for Chrome

这篇关于是否删除DOM元素删除相关的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆