Skip to content

Instantly share code, notes, and snippets.

@chrishowes
Created July 21, 2016 15:04
Show Gist options
  • Save chrishowes/70b01f783fdae0aa632fa10aeffcd6a6 to your computer and use it in GitHub Desktop.
Save chrishowes/70b01f783fdae0aa632fa10aeffcd6a6 to your computer and use it in GitHub Desktop.
Ember Action Passing
import Ember from 'ember';
export default Ember.Component.extend({
count: 0,
lastSource: 'nowhere',
show: false,
actions: {
showModal() {
this.set('show', true);
},
close() {
this.set('show', false);
},
accept(source) {
this.set('lastSource', source);
this.incrementProperty('count');
this.set('show', false);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{test-component}}
{{outlet}}
<br>
<br>
this is true
<button onclick={{action this.attrs.accept}}>Also accept</button>
<b>Hi, you've accepted {{count}} times, last time from {{lastSource}}</b>
<button onclick={{action 'showModal'}}>Show</button>
{{test-modal show=show close=(action "close") accept=(action "accept")}}
modal status {{show}}
{{#if show}}
<p>This is a test modal!</p>
<button onclick={{this.attrs.close}}>Close</button>
<button onclick={{action this.attrs.accept "outer"}}>Accept</button>
{{inner-component accept=(action this.attrs.accept "inner")}}
{{/if}}
{
"version": "0.10.1",
"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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0",
"ember-htmlbars-inline-precompile": "0.3.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment