I have used this approach in an existing app, and works well
App.ModalView = Ember.View.extend({
templateName: "modal",
title: "",
content: "",
classNames: ["modal", "fade", "hide"],
didInsertElement: function() {
this.$().modal("show");
this.$().one("hidden", this._viewDidHide);
},
// modal dismissed by example clicked in X, make sure the modal view is destroyed
_viewDidHide: function() {
if (!this.isDestroyed) {
this.destroy();
}
},
// here we click in close button so _viewDidHide is called
close: function() {
this.$(".close").click();
}
});
Here we listen the hidden
event, that is triggered when the modal is completely hidden, to destroy the object. This is important because views created programmatically, calling view.append()
, isn't destroyed. That approach ensure it.
And this is the jsfiddle with the example.