Skip to content

Instantly share code, notes, and snippets.

@cafreeman
Last active August 4, 2016 16:06
Show Gist options
  • Save cafreeman/2b021e1b72a83a5278ba184f3c84a060 to your computer and use it in GitHub Desktop.
Save cafreeman/2b021e1b72a83a5278ba184f3c84a060 to your computer and use it in GitHub Desktop.
Service-Backed Component
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
helloService: Ember.inject.service('hello-world'),
actions: {
sayHello(name) {
this.get('helloService.sayHi')(name);
}
}
});
import Ember from 'ember';
export default Ember.Service.extend({
name: null,
hello(name) {
this.set('name', name);
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{hello-world hello=(action 'sayHello')}}
<input type="text" value={{name}} onchange={{action (mut name) value="target.value"}}>
<button {{action hello name}}>Say Hello</button>
{{#if name}}
<h4>Hello {{name}}</h4>
{{/if}}
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment