Detect template render in controller?


#1

How do I detect when a template tied to a controller has been rendered?

I need to initialize a jQuery plugin.

I tried init() and reopen() in the controller without luck.

Ideas?


#2

Try didInsertElement on the view (not controller) backing the template.

i.e.

App.PostsView = Ember.View.extend({
  didInsertElement: function() {
    this.$().magic();
  }
});

for the posts template


#3

Thanks! Works like a charm


#4

I think that using event oriented for this is a better approach:

setupPlugin: function() {
   this.$().magic();
}.on('didInsertElement')

By this way you don’t have to call this._super(arguments) in the redefinition of didInsertElement, what do you think @samselikoff?


#5

I actually usually do this too, I think the naming is clearer.

The only time I’ve run into super trouble is with init, don’t think you need to with didInsertElement. But, doing it this way is safer regardless, so I like it.