Skip to content

Instantly share code, notes, and snippets.

@xm
Last active March 15, 2017 21:42
Show Gist options
  • Select an option

  • Save xm/2e13234cccfa02b2af280b7068b632b8 to your computer and use it in GitHub Desktop.

Select an option

Save xm/2e13234cccfa02b2af280b7068b632b8 to your computer and use it in GitHub Desktop.
Actions to Controllers Demo
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
click() {
this.sendAction('action', 'Component');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
buttonClicked(source) {
alert(`Controller 'buttonClicked' from ${source}`);
return true; // must literally return true and not a truthy value
},
clickFromController() {
this.send('buttonClicked', 'Controller');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
buttonClicked(source) {
alert(`Route 'buttonClicked' from ${source}`);
}
}
});
<button {{action "clickFromController"}}>Controller to Route Action</button>
{{component-button text="Component to Route Action" action="buttonClicked"}}
<button {{action "click"}}>{{text}}</button>
{
"version": "0.11.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.11.0",
"ember-data": "2.11.0",
"ember-template-compiler": "2.11.0",
"ember-testing": "2.11.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment