How to get detached() called when dynamically removing element in DOM?

Hi. We have a dynamic component to add/remove elements dynamically . When adding elements, we call BindingEngine.enhance() after insert an element in DOM, that makes attached() method of the added component called successfully. We want to get detached() called when removing an element in DOM as well. Is there a way to achieve it?

2 Likes

Take a look at this issue for a workaround https://github.com/aurelia/framework/issues/714

3 Likes

@jlee .enhance from either Aurelia or TemplatingEngine will return you a view. For that, you can call detached on it yourself.

const view = this.templatingEngine.enhance(...);

...

view.detached();
3 Likes