When routes are loading or there's an error, we have the ability to let the user know what's happening. This recipe will go over the basics on how to do this.
In a new project, create a new
students
route:$ ember g route students
The
ember generate
command will create all the necessary files for thestudents
route.Edit the
students.js
file in theapp/routes
folder. Add a new model to return:// app/routes/students.js import Ember from 'ember'; export default Ember.Route.extend({ model(){ return new Ember.RSVP.Promise(function (resolve, reject) { Ember.run.later((function() { resolve( [1,2,3,4,5,6,7,8,9]); }), 2000); }); } });
In our route file, we are returning an Ember
RSVP
promise. This promise resolves to a simple array that will be returned.Ember.run.later
is a built-in Ember method that is a part of the Ember run loop. It acts like the JavaScript'ssetTimeout()
. In this case, we are setting the timeout...