Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
actions: {
addExpense() { this.get('expense').pushObject(Ember.Object.create({amount: 100}));
}
},
expense: Ember.computed(function() {
return Ember.A([
Ember.Object.create({amount: 100}),
Ember.Object.create({amount: 100})
]);
}),
totalExpenses: Ember.computed('expense.@each.amount', function() {
return this.get('expense').reduce(function (sum, exp) {
return sum + exp.amount;
}, 0);
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<ul>
{{#each expense as |exp|}}
<li>{{exp.amount}}</li>
{{/each}}
</ul>
<b>Total: </b>{{totalExpenses}}
<br>
<br>
{{input type="button" click=(action "addExpense") value="Add 100"}}
<br>
{{outlet}}
<br>
<br>
{
"version": "0.4.17",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment