Skip to content

Instantly share code, notes, and snippets.

@vigor-rus
Last active July 22, 2019 19:09
Show Gist options
  • Save vigor-rus/4f70cc4d6d66fe3cc1fda7cde3f013a3 to your computer and use it in GitHub Desktop.
Save vigor-rus/4f70cc4d6d66fe3cc1fda7cde3f013a3 to your computer and use it in GitHub Desktop.
model inheritance in nested route
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('bands');
this.route('songs');
});
export default Router;
import Ember from 'ember';
import {A} from '@ember/array';
import EmberObject from '@ember/object';
export default Ember.Route.extend({
model() {
let obj1 = EmberObject.create(
{title: 'title1', name: 'name1'}
);
let obj2= EmberObject.create(
{title: 'title2', name: 'name2'}
);
return A([
obj1, obj2
]);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
//model() {}
});
{{#each model as |obj|}}
<li>
{{obj.name}} by <em>{{obj.title}}</em>
</li>
{{/each}}
Since reusing the model
of the parent route in child routes is a common pattern, child routes inherit the model of their parent by
default. This means we could remove the above file altogether and the page would still work.
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment