# Handling lifecycle when using compose from a view model

**URL:** <https://discourse.aurelia.io/t/handling-lifecycle-when-using-compose-from-a-view-model/4872>\
**Category:** Framework Knowledge\
**Created:** [August 11, 2022, 11:01am UTC](https://discourse.aurelia.io/t/handling-lifecycle-when-using-compose-from-a-view-model/4872 "2022-08-11T11:01:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 11, 2022, 7:39pm UTC](https://discourse.aurelia.io/t/handling-lifecycle-when-using-compose-from-a-view-model/4872/2 "2022-08-11T19:39:35Z")

</div>

I did something like this quite a while back, and it still seems to work.

```javascript
const element = here.you.create.HTMLElementFragment();
this.templatingEngine.enhance({
  element,
  bindingContext: { what: ever },
});
// grab the controller
const controller = element['au'].controller;

// later when you want to tearDown
controller.detached();
controller.unbind();

```

---

_[View the full topic](https://discourse.aurelia.io/t/handling-lifecycle-when-using-compose-from-a-view-model/4872)._
