Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Last active December 14, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samselikoff/19daf7ec343440db9d2a2c4619ef0dc9 to your computer and use it in GitHub Desktop.
Save samselikoff/19daf7ec343440db9d2a2c4619ef0dc9 to your computer and use it in GitHub Desktop.
Configurable actions
import Ember from 'ember';
export default Ember.Component.extend({
foo: 123,
'on-click'(selected) {
this.set('foo', selected);
},
actions: {
didClick() {
let selected = 'bar';
this.get('on-click').call(this, selected);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
updateFoo(val) {
this.set('foo', val);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
{{my-component}}
{{my-component on-click=(action 'updateFoo')}}
{{foo}}
<p>
<a {{action 'didClick'}} href='#'>
Click me
</a>
</p>
<p>
The value of foo is {{foo}}.
</p>
{
"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