Emberjs didInsertElement fired before DOM rendered, works only with setTimeout 0

246 views Asked by At

I have a view that renders its template into a named outlet. I use the didInsertElement hook, and there the afterRender schedule to wait for the DOM to complete. However, when I try to access the outcome of this render process, these elements are unknown. If I wrap the access in a setTimeout with time 0 (so that it runs in the next event loop cycle), it works.

App.PlaceView = Ember.View.extend({
    didInsertElement: function () {
        Ember.run.scheduleOnce('afterRender', this, function () {
            // This works
            setTimeout(
                function () {
                    // access elements
                },
                0
            );

            // Access elements here does not work
        });
    }
});

What am I doing wrong?

0

There are 0 answers