Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Init value within a component
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
model () {
return {
id: 11,
children: [
{ id: 21, name: 'A' },
{ id: 22, name: 'B' },
{ id: 22, name: 'C' }
]
};
}
});
{{my-favs data=model}}
import Ember from 'ember';
export default Ember.Component.extend({
init () {
this._super(...arguments);
// firstObject returns a[0] in Ember
const firstChild = this.get('data.children.firstObject');
if (firstChild) {
// if it's an Ember Object then
// firstChild.set('active', true)
firstChild.active = true;
}
}
});
<p>Children:</p>
<ul>
{{#each data.children as |child|}}
<li>
{{input type="checkbox" checked=child.active}}
<span>{{child.name}}</span>
</li>
{{/each}}
</ul>
{{yield}}
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment