Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Last active July 1, 2019 13:43
Show Gist options
  • Save GavinJoyce/38c1e095b59db3724d5836149ff0c36a to your computer and use it in GitHub Desktop.
Save GavinJoyce/38c1e095b59db3724d5836149ff0c36a to your computer and use it in GitHub Desktop.
Component arrays
import Ember from 'ember';
export default Ember.Component.extend({
shared: [],
nonShared: undefined,
counter: 0,
init() {
this._super(...arguments);
this.set('nonShared', []);
},
actions: {
addShared() {
let count = this.incrementProperty('counter');
this.shared.pushObject(`Shared Item ${count}`);
},
addNonShared() {
let count = this.incrementProperty('counter');
this.nonShared.pushObject(`Shared Item ${count}`);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
{{my-component}}
<hr />
{{my-component}}
<button onclick={{action 'addShared'}}>Add shared item</button>
<button onclick={{action 'addNonShared'}}>Add non-shared item</button>
Shared:
<ul>
{{#each this.shared as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
Not Shared:
<ul>
{{#each this.nonShared as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
{
"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