SimpleJ
SimpleJ

Reputation: 14798

Why aren't these Ember.js view events being fired?

I'm trying to do something when my view becomes visible, but the becameVisible event callback isn't being called.

Here is my view:

App.LessonView = Ember.View.extend({
    click: function() {
        console.log("click");
    },

    becameVisible: function() {
        console.log("becameVisible");
    },

    willClearRender: function() {
        console.log("willClearRender");
    }
});

When I click any element in the view, the click event is fired, but becameVisible and willClearRender aren't ever fired.

Is there something I'm not understanding?

Upvotes: 2

Views: 597

Answers (2)

quaertym
quaertym

Reputation: 3961

willClearRender is called before the view is rerendered. becameVisible is called when the isVisible property of the view changes to true. You check out this jsbin.

Upvotes: 1

kiwiupover
kiwiupover

Reputation: 1780

didInsertElement fires when Ember is putting the views dom into the page. willDestroyElement will fire when ember is removing the dom from the page.

App.LessonView = Ember.View.extend({
    click: function() {
        console.log("click");
    },

    didInsertElement: function() {
        console.log("didInsertElement");
    },

    willDestroyElement: function() {
        console.log("willDestroyElement");
    }
});

A few things you should be aware of when using didInsertElement 1. When the model that backs the view is changed ember will update the bindings in the current view so Ember doesn't have to reinsert the view and didInsertElement will not fire. 2. If you setup event handlers on didInsertElement like a bootstrap menu event you need to turn that binding off in the willDestroyElement event.

Upvotes: 2

Related Questions