Skip to content

Instantly share code, notes, and snippets.

@kkenan
Forked from ctusch/application.controller.js
Created February 26, 2016 22:50
Show Gist options
  • Save kkenan/025c8b3a72adc57544e0 to your computer and use it in GitHub Desktop.
Save kkenan/025c8b3a72adc57544e0 to your computer and use it in GitHub Desktop.
bind to child view
import Ember from 'ember';
export default Ember.Controller.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
childComponentProp: null,
actions: {
set: function() {
this.attrs.childComponentProp.update(3);
},
unset: function() {
this.attrs.childComponentProp.update(null);
}
}
});
child-component: {{childComponentProp}}
<br />
<button {{action 'set'}}>Set</button>
<button {{action 'unset'}}>Unset</button>
import Ember from 'ember';
export default Ember.Component.extend({
classNameBindings: ['computedClasses'],
childComponentProp: null,
computedClasses: function() {
var classes = '';
// some other stuff
if(this.get('childComponentProp') === 3) {
classes = classes + ' some-class';
}
return classes.trim();
}.property('childComponentProp'),
});
parent-component: {{childComponentProp}}
<br>
{{component "child-component" childComponentProp=(mut childComponentProp)}}
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.some-class {
color: blue
}
{
"version": "0.6.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment