O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Specifying a route's model

In the first chapter, we mentioned that route handlers provide controllers, the data needed to be displayed by templates. These handlers have a model hook that can be used to provide this data in the following format:

AppNamespace.RouteHandlerName = Ember.Route.extend({
  model: function(){
  }
});

For instance, the route contacts handler in the chapter sample loads any saved contacts from local storage as:

  model: function(){
    return App.Contact.find();
  }

We have abstracted this logic into our App.Contact model. Notice how we reopen the class in order to define this static method. As a recap of this lesson in Chapter 2, Understanding Ember.js Objects and Mixins, a static method can only be called by the class of that method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required