Skip to content

Instantly share code, notes, and snippets.

@gmarquet
Last active February 14, 2017 13:37
Show Gist options
  • Save gmarquet/3f16996f41a34066fa241fb08bcff977 to your computer and use it in GitHub Desktop.
Save gmarquet/3f16996f41a34066fa241fb08bcff977 to your computer and use it in GitHub Desktop.
Alias controller property to model
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
items: [],
totalChanged: Ember.observer('total', function() {
console.log('totalChanged');
let model = this.get('moddel');
if (model && !model.isDestroyed) {
model.set('total', this.get('total'));
}
}),
total: Ember.computed.readOnly('items.length'),
actions: {
addItem() {
this.get('items').addObject({});
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
total: attr('number')
});
<button {{action 'addItem'}}>Add item</button>
<hr>
Controller total : {{total}}<br>
Model total : {{model.total}}<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