Skip to content

Instantly share code, notes, and snippets.

@givanse
Last active May 22, 2016 15:26
Show Gist options
  • Save givanse/0cea6a415efed18be5a7 to your computer and use it in GitHub Desktop.
Save givanse/0cea6a415efed18be5a7 to your computer and use it in GitHub Desktop.
afterRenderEvent mixin
import Ember from 'ember';
export default Ember.Mixin.create({
/*
This hook is guaranteed to be executed when the root element of this view has been inserted into the DOM.
*/
didInsertElement : function(){
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent : Ember.K
});

Create a mixin and use the code in after-render.js

ember generate mixin after-render

To use the mixin in a view, do:

import AfterRender from '../mixins/after-render';

export default Ember.View.extend(AfterRender, {
    afterRenderEvent: function() { 
        // JQuery sauce 
    }
});

Note:

Since 1.8.0-beta.1 the behaviour has changed. Now the event triggers first in the children and from there it bubbles up to the parent. See: emberjs/ember.js#5639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment