Skip to content

Instantly share code, notes, and snippets.

@mapohjola
Last active February 8, 2017 18:26
Show Gist options
  • Save mapohjola/92a6e499c6bdd8fdd0bc91b9c210d061 to your computer and use it in GitHub Desktop.
Save mapohjola/92a6e499c6bdd8fdd0bc91b9c210d061 to your computer and use it in GitHub Desktop.
modelName
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
modelName: Ember.computed(function() {
return this.get('model._internalModel.modelName');
}),
modelName2: Ember.computed(function() {
return this.get('model.constructor.modelName');
}),
modelFor: Ember.computed(function() {
return this.store.modelFor('my-model')
})
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string')
});
import Ember from 'ember';
export default Ember.Route.extend({
store: Ember.inject.service(),
model() {
return this.get('store').createRecord('my-model', {name: 'test'});
}
});
<h1>Model with name property {{model.name}}</h1>
<br>
<br>
This is with constructor in template: {{model.constructor.modelName}}<br>
This is computed with constructor: {{modelName2}}<br>
This is computed with _internalModel: {{modelName}}<br>
This is with internalModel in template: {{model._internalModel.modelName}}<br>
This is modelFor my-model: {{modelFor}}<br>
<br>
<br>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment