Skip to content

Instantly share code, notes, and snippets.

@pswai
Last active February 6, 2017 01:12
Show Gist options
  • Save pswai/0333d6455ab026c8277f4a199cd163c1 to your computer and use it in GitHub Desktop.
Save pswai/0333d6455ab026c8277f4a199cd163c1 to your computer and use it in GitHub Desktop.
Setting default value for object-/array- type property
import Ember from 'ember';
export default Ember.Component.extend({
items: Ember.computed(() => []),
actions: {
addItem() {
const items = this.get('items');
items.pushObject(`Item ${items.length}`);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
<div>
<p>Foo-bar 1</p>
{{foo-bar}}
</div>
<div>
<p>Foo-bar 2</p>
{{foo-bar}}
</div>
<button type="button" onclick={{action 'addItem'}}>Add Item</button>
<ul>
{{#each items as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
{
"version": "0.10.6",
"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.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment