Skip to content

Instantly share code, notes, and snippets.

@cafreeman
Last active May 14, 2018 18:28
Show Gist options
  • Save cafreeman/794d7e2b8b85bd88979fe9f03f4ebdae to your computer and use it in GitHub Desktop.
Save cafreeman/794d7e2b8b85bd88979fe9f03f4ebdae to your computer and use it in GitHub Desktop.
Watching objects in template
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
this.thingsByName = {};
},
actions: {
push(name) {
console.log(name);
this.set(`thingsByName.${name}`, Math.random());
this.set('inputValue', '');
}
}
});
<input type="text" value={{inputValue}} onchange={{action (mut inputValue) value="target.value"}}/>
<br>
<button onclick={{action 'push' inputValue}}>Add To Object</button>
<ul>
{{#each-in thingsByName as |name thing|}}
<li>{{name}} - {{thing}}</li>
{{/each-in}}
</ul>
{
"version": "0.13.1",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment