Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Is there a way to "unbootstrap" an element & module? #6180

Closed
jancarloviray opened this issue Feb 7, 2014 · 5 comments
Closed

Is there a way to "unbootstrap" an element & module? #6180

jancarloviray opened this issue Feb 7, 2014 · 5 comments

Comments

@jancarloviray
Copy link

I bootstrap an element & module with this:
angular.bootstrap(elemenent, ['appName']);

What if I want to "unbootstrap" it?

@btford
Copy link
Contributor

btford commented Feb 7, 2014

AFAIK, not easily.

Your could clone the DOM tree, remove the bootstrapped bits, and then add the cloned DOM back in.

What is it that you're trying to do? There might be a better approach.

@jancarloviray
Copy link
Author

I am using Rendr, which is like a Backbone app. Each view is "recreated" every time a user interacts with the page.

Everytime I render the page, my "initialize" creates an angular.module(...) to bootstrap the app & its controllers.

angular.bootstrap re-adds them (an entirely new instance of DOMelement, yet same contents & etc) and causes an "already boostrapped" error

Rendr uses Backbone routes in client, so I can't really use angular routes to manage things.

@btford
Copy link
Contributor

btford commented Feb 7, 2014

I don't think Rendr is meant to be used with Angular. Angular should manage DOM updates for your app. If you're constantly disabling this feature (by un-bootstrapping the app), why use Angular at all? Is there something I'm missing?

@jancarloviray
Copy link
Author

We're planning using AngularJS for its dom-binding features, modularity and scalability.

What I was planning to do is to have major views bootstrap a nested app while inside the global ng-app (body). In initial load, load all global services in parent ng-app. Then on every view-initialize, bootstrap a nested app, then once the view gets trashed, unbootstrap it, while keeping the parent ng-app intact. I need to unbootstrap it to clean resources.

With regards to Rendr, if a site is visited directly by its url, Rendr uses Express in backend (for SEO). If a user visits links through the site, it uses Backbone. Perhaps I can do a fork to use Angular's router instead of backbone's.

Another possible solution (i think) is to load controllers, factories, services, etc dynamically. Would that be possible with AngularJS?

Basically if(notExists)loadThisController()

Not entirely sure how to get around this. I'm building the foundation of a very big enterprise "webapp." And I am stuck with Rendr, so I cannot convert to Express/Angular stack freely.

@btford
Copy link
Contributor

btford commented Feb 7, 2014

@jancarloviray you could lazily load code and instantiate it with $controller. There are some articles on strategies for doing this around the web.

The only way to "unbootstrap" parts of angular are to remove it from the DOM. The good news is that angular does the cleanup for you, so long as you use scopes and jQuery/jqLite's remove() method.

I'd recommend checking out StackOverflow or the IRC channel for more advice. This is possible, but it's outside the scope of angular core.

Closing this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants