Binding JQuery events after the template is rendered

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.

1 Like

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

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
    });
  },

Thank you so much, this worked.

By template i mean the view.

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 …

1 Like