What is the proper way in AngularJS to disconnect bindings?

AngularJS中断开绑定的正确方法是什么?

I have a none-angular application which is loading a component that uses angularjs to do data-binding. At some point I want to destroy the component and want to be sure that there are no memory leaks. How do I tell angular to remove all event listeners from that part of the DOM?

我有一个无角度的应用程序,它正在加载一个使用angularjs进行数据绑定的组件。在某些时候,我想破坏组件,并希望确保没有内存泄漏。如何告诉angular从DOM的那一部分删除所有事件监听器?

Would $(node).remove() do the trick, or does angular do other things in memory that need to be cleaned up...? Any other tips on avoiding mem-leaks in angular would be appreciated.

$(node).remove()会不会这样做,或者会在内存中做其他需要清理的东西......?关于避免角度内泄漏的任何其他提示将不胜感激。

1 个解决方案

#1


10

Just removing a DOM element that has a Scope with something like remove() will not get rid of the Scope in memory. You can confirm this by removing an element and looking in Batarang, or by getting the parent scope and examining it's children. You'll see the scope is still there.... So you'll also want to call $destroy() on the Scope itself.

只需删除具有类似remove()之类的Scope的DOM元素,就不会删除内存中的Scope。您可以通过删除元素并查看Batarang,或通过获取父范围并检查其子项来确认这一点。你会看到范围仍然存在....所以你也想在Scope本身上调用$ destroy()。

More information about $destroy() can be found here.

有关$ destroy()的更多信息,请点击此处。

EDIT: One thing I'm not sure of, is if it deletes the scope entirely, or just disconnects it and lets JavaScript GC take care of the rest.

编辑:我不确定的一件事是,它是否完全删除了作用域,或者只是断开它并让JavaScript GC处理其余部分。

更多相关文章

  1. 五十行javascript代码实现简单的双向数据绑定
  2. Knockout.js - 在通过observable设置值时阻止更改事件绑定
  3. jquery 更改angularJS input 内容导致绑定失效的解决办法
  4. 模板渲染后KnockoutJS绑定事件
  5. Python是如何进行内存管理的
  6. python之内存概念
  7. 用于Python项目的低内存和最快查询数据库
  8. 在Python中的大文件中拆分行的内存问题
  9. 使用python 3.6将多个文件并行加载到内存中的最佳方法是什么?

随机推荐

  1. Android(安卓)热补丁技术——资源的热修
  2. 关于 android app 返回键模拟 home键 功
  3. android前后摄像头切换
  4. Android SDK安装更新Failed to fetch URL
  5. Android中常见Intent习惯用法-上篇(附源
  6. iphone Android JS的使用
  7. Android项目发布 ---- Jcenter篇
  8. android为文本框设置背景资源-shape
  9. Android简易实战教程--第三十九话《Chron
  10. .Net 转战 Android 4.4 日常笔记(5)--新软