Skip to content

Instantly share code, notes, and snippets.

@Panman82
Last active July 27, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Panman82/acc1be18eb9213778e1e2632a4a10f27 to your computer and use it in GitHub Desktop.
Save Panman82/acc1be18eb9213778e1e2632a4a10f27 to your computer and use it in GitHub Desktop.
Closure action target option and context
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'button'
});
import Ember from 'ember';
export default Ember.Controller.extend({
name: 'Ember Twiddle',
init() {
this._super(...arguments);
this.set('foobar', Ember.Object.create({
name: 'Foobar Obj',
myName() {
alert(
'My name is: ' +
this.get('name')
);
}
}));
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
table {
border-collapse: collapse;
width: 100%;
}
table, th, td {
border: 1px solid black;
}
thead tr {
background-color: lightgray;
}
th, td {
padding: 3px;
}
<h1>Welcome to {{name}}</h1>
<p>Expecting <code>"Foobar Obj"</code> in the <code>alert()</code>, <em>not</em> <code>"Ember Twiddle"</code>.</p>
<button {{action foobar.myName target=foobar}}>
Works
</button>
{{#my-button click=(action foobar.myName target=foobar)}}
Doesn't Work
{{/my-button}}
{
"version": "0.10.5",
"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.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment