Reputation: 261
I'm writing a script that adds a tutorial on top of an Ember.js app. The problem is that the script is referencing elements that should be loaded by the Ember app. When the script runs, the elements are not yet loaded, even though the script is running onload
.
How do I determine if Ember is done loading the page? I know the controller/template/component names, but I have no clue how to specify that the script should run AFTER they're done loading.
Upvotes: 0
Views: 326
Reputation: 12872
ready
event from Ember.Application
is for Ember app root elements loaded.
Called when the Application has become ready, immediately before routing begins. The call will be delayed until the DOM has become ready.
Reference: http://emberjs.com/api/classes/Ember.Application.html#event_ready
In app.js
App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
ready: function() {
//this place you can write down your javascript code.
},
Resolver
});
If you know the route, then try didTransition
didTransition() {
Ember.run.scheduleOnce('afterRender', this, function () {
//your script code
});
}
reference:http://emberjs.com/api/classes/Ember.Route.html#event_didTransition.
If you know the Component, then try didInsertElement
reference: http://emberjs.com/api/classes/Ember.Component.html#event_didInsertElement
Upvotes: 0
Reputation: 6947
Sounds like you need to schedule your code to run after Ember has rendered. Do it like this:
Ember.run.scheduleOnce('afterRender', this, yourFunction);
Upvotes: 3