Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovrmrw/0157681f18f7348a018c to your computer and use it in GitHub Desktop.
Save ovrmrw/0157681f18f7348a018c to your computer and use it in GitHub Desktop.
sample: Knockout in Node+Express
declare var ko: any;
class Formula {
a: any = ko.observable(3);
b: any = ko.observable(4);
sum: any = ko.observable(null);
// 'sum' is changed with this ko.computed().
private controlSum: Function = ko.computed(() => {
var a: number = Number(this.a()), // Don't forget to cast to number.
b: number = Number(this.b()); // Don't forget to cast to number.
this.sum(a + b);
});
}
var formula = new Formula();
ko.punches.enableAll(); // *Write this before ko.applyBindings().*
ko.applyBindings(formula);
<% include header %>
<h1><%-title %></h1>
<p>Welcome to <%-title %></p>
<input data-bind="textInput: a" />
<div>a = {{ a }}</div>
<input data-bind="textInput: b" />
<div>b = {{ b }}</div>
<div>a + b = {{ sum }}</div>
<% include footer %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment