Skip to content

Instantly share code, notes, and snippets.

@ivanvanderbyl
Created August 4, 2015 03:16
Show Gist options
  • Save ivanvanderbyl/fcde2819258f2de26685 to your computer and use it in GitHub Desktop.
Save ivanvanderbyl/fcde2819258f2de26685 to your computer and use it in GitHub Desktop.
Data Down, Actions Up example
export default Ember.Component.extend({
count: 0,
actions: {
incrementCount: function() {
this.set('count', this.get('count') + 1);
if(this.attrs['on-change']) {
this.attrs['on-change'](this.get('count'));
}
}
}
});
{{my-counter count=controller.count on-change=(action "handleCounterChange")}}
// controllers/index.js
export default Ember.Controller.extend({
// Count prop bound to my-counter component.
count: 1,
actions: {
handleCounterChange(newCount) {
this.set('count', newCount);
}
}
});
<p>Current +1s: {{count}}</p>
<button {{action "incrementCount"}}>+1 Me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment