beforeremove
An event called only on component’s elements before they are removed from the document if live binding is performing the removal. It can be listened to within a component’s events object or on a component element with on:event bindings. This is an additional special event only on component elements. Check out [can-dom-mutate//events/events] for other mutation events.
Deprecated 4.0
Use connectedCallback instead. See Migrating to CanJS 4’s inserted/removed event section for more information.
"{element} beforeremove": function(element, event)
Listens to when the component element is removed.
This is commonly used for cleaning up and tearing down a component.
For example, the following might remove the component’s ViewModel from a parent component’s ViewModel:
import canViewModel from "can-view-model";
import Component from "can-component";
Component.extend({
tag: "my-component",
events: {
"{element} beforeremove": function() {
canViewModel( this.element.parentNode )
.removePanel( this.viewModel );
}
}
});
Parameters
- element
{HTMLElement}
:The component element.
- event
{Event}
:The
beforeremove
event object.
on:beforeremove="CALL_EXRESSION"
Uses on:event bindings to listen for a component’s
beforeremove
event.
<my-panel on:beforeremove="removePanel(scope.viewModel)"/>
Parameters
- CALL_EXRESSION
{Call Expression}
:A call expression that calls some method when the event happens.