Destroy Gantt instance in Angular2


Thank you for your amazing job and your great products ! I’m trying to use your Gantt product on Angular2, according to your good tutorial. I’m new to Angular2.

Everything works fine, but I’m trying to do a multi Gantt app, and gantt instance (created with gantt.init()) doesn’t seem to be cleared when I change page and go to another Gantt planning view. I can clear a Gantt planning by calling gantt.clearAll(), but gantt object is probably still here.

For example, If I create a new task, it’s created in all gantt planning page I visited before !

I think I should destroy gantt instance in ngOnDestroy() function each time I leave a Gantt planning page.

Is there a way to do that ? I don’t see any method to do that in your doc.

Thank you


If you load data by gantt.parse(object, “json”), gantt doesn’t create a copy with this object, but changes the loaded object.
To avoid it, you should prohibit the opportunity to parse data object. Please convert json before loading:

gantt.parse(JSON.stringify(data), "json");


thank you for your answer. Unfortunatly, that wasn’t the answer I was expecting. Maybe my question wasn’t precise enough.

I created a codeshare to show you my current component’s code :

And I did a little drawing to explain the current behavior, and the possible solutions I have in mind (maybe it’s wrong) :

It’s very strangle, it seems that previous gantt instances are still there and do repeat all CRUD operations, on all previously visited planning pages.

For example, if I visit planning page 1, 2 and after 3, and I create a new task on 3rd planning page, this task is created for planning page 3, but also for 1 and 2 !!

If I visit a planning page, leave this page, and come back to this page to create a new task, it’s created twice on the page !

Maybe I have to destroy the gantt instance in ngOnDestroy() function, but I don’t know how to do that, you don’t have destroy method in your API.

I finally found a way, according to your documentation :

ngOnDestroy() {

It works fine when I load different views.

i have the same problem can you explain more what you did