Reputation: 5552
I have this code in a route:
import Ember from 'ember';
export default Ember.Route.extend({
isEditing: true,
beforeModel: function() {
return Ember.$.getScript('//api.filestackapi.com/filestack.js');
}
});
But is this the correct way, will it download this file every time a user transitions to this route?
I tried this solution, but in that run loop the DOM is already rendered, but I need this file to render the page, so that does not work. I also tried to remove the Run loop call, but it seems to no longer work in Ember 2.7 (I got a deprecated warning and the app just failed to load anything!).
Upvotes: 0
Views: 98
Reputation: 12872
Yes. Your approach is right. thats what described in guides too for beforeModel
hook.
You can return a promise from this hook to pause the transition until the promise resolves (or rejects). This could be useful, for instance, for retrieving async code from the server that is required to enter a route.
http://emberjs.com/api/classes/Ember.Route.html#method_beforeModel
Upvotes: 1