Skip to content

Instantly share code, notes, and snippets.

@jhoye
Last active December 20, 2017 18:03
Show Gist options
  • Save jhoye/4ccbbd152fe14e612eb6e8574776e647 to your computer and use it in GitHub Desktop.
Save jhoye/4ccbbd152fe14e612eb6e8574776e647 to your computer and use it in GitHub Desktop.
Component Interaction
import Ember from 'ember';
export default Ember.Component.extend({
// required parameters
output: null,
sendHandler: null,
input: '',
actions: {
send() {
this.sendAction('sendHandler', this.get('input'));
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return Ember.Object.create({
output1: '',
output2: ''
});
},
actions: {
receiveComponent1(text, componentModel) {
this.controller.model.set('output2', text);
// or:
//this.modelFor('index').set('output2', text);
// or:
//this.get('output').set('output2', text);
},
receiveComponent2(text, componentModel) {
this.controller.model.set('output1', text);
}
}
});
<h1>Component Interaction</h1>
{{outlet}}
{{yield}}
<div>
{{input
value=input
key-up="send"}}
</div>
<div>
{{output}}
</div>
<hr>
{{#input-output
output=model.output1
sendHandler="receiveComponent1"}}
<h2>Component 1</h2>
{{/input-output}}
<hr>
{{#input-output
output=model.output2
sendHandler="receiveComponent2"}}
<h2>Component 2</h2>
{{/input-output}}
{
"version": "0.10.2",
"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