如何摧毁angularjs应用程序? [英] How to destroy an angularjs app?
问题描述
我需要能够加载/卸载应用程序的角度动态,而不会造成内存泄漏。在jQuery中,你可以做 $(#elementHoldingMyWidget),删除();
和适当的毁灭code被执行,事件处理程序绑定等。
I need to be able to load/unload angular applications dynamically without causing memory leaks. In jQuery you can do $("#elementHoldingMyWidget").remove();
and the proper destruction code gets executed, event handlers are unbound etc.
我一直无法找到的角文档提一旦它被自举拆除一个应用程序的可能性东西。
I've been unable to find anything in the angular docs mentioning the possibility of tearing down an app once it's been bootstrapped.
我的第一次尝试是摧毁rootScope像这样:
My 1st attempt was to destroy the rootScope like so:
var rootScope = $("body").scope();
rootScope.$destroy();
但是,这似乎并没有工作,我不知道如何喷油器和服务将被清理,即使它没有。
But this doesn't seem to be working, and I'm not sure how the injector and services would be cleaned up even if it did.
应如何做?
推荐答案
那么,这个帖子:
https://github.com/angular/angular.js/问题/ 1537#issuecomment-10164971
声称没有官方应用推倒(在写作的时候),但是你可以清空元件保持应用程序像这样:
claims that there is no 'official' app tear down (at the time of writing), but you can just empty the element holding the app like so:
$('body').empty();
如果这不是你在找什么你可以通过这些步骤暂时解决撕裂你的应用程序下来:
https://github.com/angular/angular.js/issues/1537 #issuecomment-10184033
If this is not what you are looking for you can go through these steps for a temporary solution to tearing your app down: https://github.com/angular/angular.js/issues/1537#issuecomment-10184033
这篇关于如何摧毁angularjs应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!