Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a loading screen while model in application route is being fetched

Tags:

ember.js

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.

like image 317
corsen Avatar asked Mar 23 '14 00:03

corsen


People also ask

How to show a loading screen while initializing the application?

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.

How to display a loading screen between routes in react-router?

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:

What happens to the loading message when the application is ready?

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.

How to display a loading screen while the Dom is rendering with react?

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.


1 Answers

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

like image 66
Matthew Blancarte Avatar answered Sep 20 '22 05:09

Matthew Blancarte