Dougui
Dougui

Reputation: 7240

Do something when the DOM is completly loaded with ember

I'm working with an Ember 2.1.0 application. I want to apply JQuery Steps when the dom is ready. When I do this :

import Ember from 'ember';

export default Ember.Controller.extend({
  trigger: function() {
    console.log($('#subscription-form').length);
  }.on('init')
});

This code show a length of 0. When I do it later, the length is 1.

Can I trigger something when the dom completly loaded? Something similar as $(document).ready in JQuery?

Should I use a component? What are best practices? Is there something somewhere in the documentation?

Upvotes: 0

Views: 37

Answers (1)

Daniel
Daniel

Reputation: 18692

You could create another component and run jQuery in its didInsertElement hook or you could try:

trigger: function() {
  Ember.run.scheduleOnce('afterRender', this, function() {
    console.log($('#subscription-form').length);
  });
}.on('init')

Upvotes: 1

Related Questions