Skip to content

Instantly share code, notes, and snippets.

@sglanzer-deprecated
Last active April 8, 2018 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sglanzer-deprecated/209d2ea37fb773b47c794e9feda115a7 to your computer and use it in GitHub Desktop.
Save sglanzer-deprecated/209d2ea37fb773b47c794e9feda115a7 to your computer and use it in GitHub Desktop.
Arbitrary properties set via an object hash
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super(...arguments)
if (this.hash) {
Object.keys(this.hash).forEach((key) => {
Ember.defineProperty(this, key, Ember.computed.alias(`hash.${key}`))
})
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
dataDriven: {
foo: 'foo',
bar: 'bar'
}
});
Six one way...
{{my-component
foo='foo'
bar='bar'
}}
<br>
...half a dozen the other
{{my-component
hash=dataDriven
}}
<div>{{foo}}</div>
<div>{{bar}}</div>
{
"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