Skip to content

Instantly share code, notes, and snippets.

@villander
Last active April 8, 2017 03:52
Show Gist options
  • Save villander/a5f88a0c6a79ed5e05f0d38cdd0a852b to your computer and use it in GitHub Desktop.
Save villander/a5f88a0c6a79ed5e05f0d38cdd0a852b to your computer and use it in GitHub Desktop.
example
import Ember from 'ember';
export default Ember.Component.extend({
// 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);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
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|}}
{{ui.child data=item}}
{{/each}}
{{/parent-component}}
<br>
<br>
<button {{action "click"}}>Mano</button>
{{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