Press "Enter" to skip to content

How to use modelFor correctly in Ember.js

The modelFor method needs the route defined according to its hierarchy. So if router.js looks like the following: {
                    this.route('org', {path: 'org/:id'}, function() {
                      this.route('repo', {path: ':repoid'}, function() {

Here’s how to access repo’s model in the `issues` route:

model() {
                    let repoId = this.modelFor('org.repo').repoid;

The first parameter needs the route according to its position in the hierarchy separated by a period.

Just writing `this.modelFor(‘repo’)` will return undefined because that’s not a route specified in the upper most level of the router. It’s a child route and must be written out as so.

Leave a Reply

Your email address will not be published. Required fields are marked *