Skip to content

Instantly share code, notes, and snippets.

@workmanw
Created October 27, 2015 16:00
Embed
What would you like to do?
Yielding Actions
<h1>Welcome to my counter</h1>
<br>
{{#x-counter as |count increment decrement|}}
The count is: {{count}} <br><br>
{{x-button label="increment" on-click=increment}}
{{x-button label="decrement" on-click=decrement}}
{{/x-counter}}
import Ember from 'ember';
export default Ember.Component.extend({
label: '',
actions: {
click() {
this.attrs['on-click']();
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
totalCount: 0,
actions: {
increment() {
this.incrementProperty('totalCount');
},
decrement() {
this.decrementProperty('totalCount');
}
}
});
<button {{action "click"}}>{{label}}</button>
{{yield totalCount (action "increment") (action "decrement")}}
{
"version": "0.4.14",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment