Skip to content

Instantly share code, notes, and snippets.

@kalyco
Last active August 29, 2015 14:22
Show Gist options
  • Save kalyco/f980cc1d0072b74eb06d to your computer and use it in GitHub Desktop.
Save kalyco/f980cc1d0072b74eb06d to your computer and use it in GitHub Desktop.
Binds the field to a property in the controller and lets Ember handle keeping things updated. In this example a controller is set up with 2 properties 'number' and 'timesTwo'
// in the controller
App.NumberController = Ember.ObjectController.extend({
number: 1,
timesTwo: function() {
return Number(this.get('number')) * 2;
}.property('number') //tells it to treat it as a dynamic property that updates whenever number updates.
});
//in the template
{{input type="text" value=number size=50}} x2 = {{timesTwo}}
//because we are able to bind properties in templates,
//we don't have to worry about making sure every event updates every
// field that might be affected.
//You just update the part you want and let Ember handle the rest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment