Skip to content

Instantly share code, notes, and snippets.

@acorncom
Last active November 20, 2016 02:33
Show Gist options
  • Select an option

  • Save acorncom/65154b56f02cd0ebba251ead3c15e5c1 to your computer and use it in GitHub Desktop.

Select an option

Save acorncom/65154b56f02cd0ebba251ead3c15e5c1 to your computer and use it in GitHub Desktop.
template context / actions
import Ember from 'ember';
export default Ember.Component.extend({
name: "George",
actions: {
howdy() {
alert("howdy from grandparent");
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
howdy() {
alert("howdy from my-child");
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
name: "Sam",
actions: {
howdy() {
alert("howdy from my-parent");
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
howdy() {
alert("howdy from app");
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<button {{action 'howdy'}}>App Howdy</button>
<br>
{{#grand-parent as |gpName|}}
<h1>GP: {{gpName}}</h1>
<button {{action 'howdy'}}>App Howdy</button>
{{#my-parent as |pName|}}
<h2>P: {{pName}}</h2>
<button {{action 'howdy'}}>App Howdy</button>
{{my-child gp=gpName p=pName}}
{{/my-parent}}
{{/grand-parent}}
<button {{action 'howdy'}}>GP Howdy</button>
{{yield name}}
<button {{action 'howdy'}}>Child Howdy</button>
<h3>C: {{gp}}</h3>
<h3>C: {{p}}</h3>
<button {{action 'howdy'}}>Parent Howdy</button>
{{yield name}}
{
"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