Given a application route like this:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve) {
setTimeout(function() {
resolve();
}, 3000);
});
}
});
How do I show a loading template while this model hook is waiting?
I tried something like this:
<script type="text/x-handlebars" id="loading">
<h3>Loading...</h3>
</script>
But this only displays when a sub route of the application is loading. How do I show a loading template when the application itself is still loading?
Thank you.
You may want to show a loading screen while initializing the application. The solution to everything in Blazor is to create a component! In this case, the component will load the data asynchronously and display a loading message meanwhile.
It is a good practice to display a loading screen while you prepare your page to display. It is very easy to display a simple loading indicator between routes in react-router. Step 1: Create a React application using the following command: Step 2: After creating your project folder i.e. foldername, move to it using the following command:
Once the data is loaded, it replaces the loading message with the actual content. So, if you wrap the main component (surely the Router) by this loading component, the user will see the loading message until the application is ready.
To display a loading screen while the DOM is rendering with React, we can add a loading state into our React component. Then we can display what we want depending on whether the component is done loading or not.
You could make use of some sort of loading overlay (which could be some static html/css) and the afterModel
route hook:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return new Ember.RSVP.Promise(function(resolve) {
setTimeout(resolve, 3000);
});
},
afterModel: function (model, transition) {
$('.loading-overlay').fadeOut();
}
});
You would have to determine the best place to put your overlay, but this should work.
Working example: http://jsbin.com/rixukune/3
Take a look at this hook's details here in the docs: http://emberjs.com/api/classes/Ember.Route.html#method_afterModel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With