Last active
August 29, 2015 14:07
-
-
Save ovrmrw/0157681f18f7348a018c to your computer and use it in GitHub Desktop.
sample: Knockout in Node+Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 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