Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Created February 3, 2017 10:58
Show Gist options
  • Select an option

  • Save GavinJoyce/bf24503d9d5ecfec5bd231eb6b0c2107 to your computer and use it in GitHub Desktop.

Select an option

Save GavinJoyce/bf24503d9d5ecfec5bd231eb6b0c2107 to your computer and use it in GitHub Desktop.
Actions (ember map)
import Ember from 'ember';
export default Ember.Controller.extend({
counter: 0,
sayHi() {
console.log('hi', this);
},
incrementCounter() {
this.incrementProperty('counter');
},
actions: {
incrementCounterAction(delta=1) {
this.set('counter', this.get('counter') + delta);
}
}
});
<button onclick={{sayHi}}>say hi</button>
{{counter}}
<button onclick={{action incrementCounter}}>
increment
</button>
<button onclick={{action actions.incrementCounterAction}}>
increment
</button>
<button onclick={{action 'incrementCounterAction'}}>
increment
</button>
<button onclick={{action 'incrementCounterAction' 2}}>
increment by 2
</button>
<button onclick={{action (action 'incrementCounterAction' 3)}}>
increment by 3
</button>
{
"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": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment