Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenweber/3e62224faeca71fc464c68442dba5e8e to your computer and use it in GitHub Desktop.
Save jenweber/3e62224faeca71fc464c68442dba5e8e to your computer and use it in GitHub Desktop.
Invoking actions on component collaborators
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
import { inject as service} from '@ember/service';
export default Ember.Component.extend({
myService: service()
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Service.extend({
someFunc() {
alert('someFunc worked');
},
actions: {
someAction() {
alert('some action worked');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component}}
<br>
<br>
{{yield}}
<button {{action onConfirm}}>Try it</button>
<button {{action "someFunc" target=myService}}>SomeFunc</button>
<button {{action "someAction" target=myService}}>SomeAction</button>
<br><br>
Original example - someAction
{{#button-with-confirmation
text="Click to send your message."
onConfirm=(action "someAction" target=myService)
as |confirmValue| }}
{{input value=confirmValue}}
{{/button-with-confirmation}}
<br><br>
Original example - someFunc (doesn't render due to error)
{{#button-with-confirmation
text="Click to send your message."
onConfirm=(action "someFunc" target=myService)
as |confirmValue| }}
{{input value=confirmValue}}
{{/button-with-confirmation}}
{
"version": "0.14.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment