Dispose Angular 2 App or Component

Is there anyway to dispose angular2 app or component? I’m doing a mixed ASP.NET MVC and Angular 2 app which ASP.NET MVC loads partial views including Angular 2 App. Now I need a close button for each partial view to remove itself from the DOM and dispose loaded angular 2 inside the view to avoid memory leak. Is there anyway to kill angular 2 app ?

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

update

.dispose() is destroy() since beta.16

original

When you bootstrap a component, you get a ComponentRef of the root component (AppComponent). To dispose it call its dispose() method:

bootstrap(AppComponent, [ROUTER_PROVIDERS,
    provide(LocationStrategy, {useClass: HashLocationStrategy}])
    .then((ref) => {
      setTimeout(()=> {
        ref.dispose();
      }, 3000);
    });
  .catch(err => console.error(err));

(You can assign the ref variable somewhere for later reuse. This is just to demonstrate that an Angular application can be disposed.)

Plunker example