Skip to content

Instantly share code, notes, and snippets.

@HenryVonfire
Last active April 1, 2016 03:40
Show Gist options
  • Save HenryVonfire/b9cdaf69a9e08523df06 to your computer and use it in GitHub Desktop.
Save HenryVonfire/b9cdaf69a9e08523df06 to your computer and use it in GitHub Desktop.
Closure Actions
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Closure actions',
result: 'without news',
actions:{
myAction(){
this.set('result', 'received!');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
result: <b>{{result}}</b>
{{level-one myActionLevelOne=(action 'myAction')}}
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
});
{{!using (action actionName)}}
{{!the action names can be the same}}
{{level-two myActionLevelOne=(action myActionLevelOne)}}
import Ember from 'ember';
export default Ember.Component.extend({
actions:{
myButton(){
return this.get('myActionLevelThree')();
}
}
});
<button {{action 'myButton'}}>Raise action</button>
import Ember from 'ember';
export default Ember.Component.extend({
});
{{!using attrs.actionName instead of (action actionName)}}
{{level-three myActionLevelThree=attrs.myActionLevelOne}}
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment