FunkyCodeMonkey
FunkyCodeMonkey

Reputation: 59

How to force Aurelia to destroy/recreate a view/viewModel pair without using router

It came as a surprise when starting out with Aurelia that if.bind doesn't result in a child view/viewModel getting destroyed. It does go through a bind/unbind attached/detached cycle, and I can see how this makes sense for some scenarios. But I would also like the ability to completely destroy the view/viewModel and recreate it from scratch. I've created a plunker that demonstrates my best effort using if.bind. I'm looking for suggestions on how to have the <my-other-element> completely destroyed. Thanks!

Upvotes: 4

Views: 1149

Answers (1)

Joseph Gabriel
Joseph Gabriel

Reputation: 8520

Looks like you can use the <compose> element to treat the custom element as a view/view model and therefore use transient creation behavior. See compose documentation

plunker: https://plnkr.co/edit/vKsQsHKsIp4vTVjG5G7f?p=preview

<template if.bind="someBoolean">
  <compose view-model="my-other-element.js"></compose>
</template>

Upvotes: 1

Related Questions