Binding JQuery events after the template is rendered


#1

Hi guys,

I am trying to bind jquery events to the HTML elements in my template once the template has rendered. The only hook I can find is the init() hook in template, there is a didRender hook in Ember component, that allows me to do this but this won’t be a very good approach to use component instead of Ember Template.

Kindly tell me if there is any other way to do this through templates.


#2

what you mean by template ? you definitely should use component for this


#3

I believe you could do something like this in your controller:

  init: function () {
    this._super();
    Ember.run.schedule("afterRender",this,function() {
      //... post-render setup here
    });
  },

#4

Thank you so much, this worked.


#5

By template i mean the view.


#6

Generally, it’s recommended to use components for registering these types of JQuery events (as opposed to doing it with controllers) as component life cycles are clearer and cleaner. Controllers don’t always work the way you would initially expect, which can lead to your event listeners being registered unexpectedly …