Closure Action Example
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
No need to define save method in component actions hash since it is passed from template.
<button {{action 'save'}}>Save</button>
{{yield}}
<h1>Welcome to {{appName}}</h1>
<br>
{{my-component save=(action 'save')}}
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
actions:{
saveInRoute(){
console.log('save in route');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions:{
save(){
console.log('save in controller');
this.send('saveInRoute');
},
savemore() {
console.log('save more in controller');
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions:{
save(){
console.log('save in component');
this.sendAction('save');
this.sendAction('savemore');
}
}
});