Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save angelomachado/cce0510824bee067f1eaca390d116307 to your computer and use it in GitHub Desktop.
Save angelomachado/cce0510824bee067f1eaca390d116307 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'button',
// On click we call the action passed down to us from the parent
click() {
let data = this.get('data');
this.get('onaction')(data);
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
// We pass this action to the child to call at it's discretion
parentAction(childData) {
// alert('Data from child-component: ' + childData);
console.log(childData);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
// ui: Ember.Object.create([{id:1, item:7}, {id:2, item: 9}]),
// model: Ember.Object.create([{id:1, item:7}, {id:2, item: 9}])
model: [{id:1, item:7}, {id:2, item: 9}]
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{#parent-component as |ui|}}
{{#each model as |item index|}}
{{log ui.child }}
{{ui.child data=item index=index}}
{{/each}}
{{/parent-component}}
<br>
<br>
{{yield (hash
child=(
component 'child-component'
onaction=(action 'parentAction')
)
)}}
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment