CHS CHS - 7 months ago 138
AngularJS Question

How to destroy an angularjs app?

I need to be able to load/unload angular applications dynamically without causing memory leaks. In jQuery you can do

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.

My 1st attempt was to destroy the rootScope like so:

var rootScope = $("body").scope();

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.

How should this be done?


UPDATE March 10, 2013: I found that $('body').empty(); does not tear down the app. It still lives.


Well, this post: 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:


If this is not what you are looking for you can go through these steps for a temporary solution to tearing your app down: