Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created February 19, 2015 18:05
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 idmontie/e0c0a048e672964d5d12 to your computer and use it in GitHub Desktop.
Save idmontie/e0c0a048e672964d5d12 to your computer and use it in GitHub Desktop.
KnockoutJS Two Way Data Binding Example
<input data-bind="value: firstName" placeholder="first name"/>
<input data-bind="value: lastName" placeholder="last name"/>
<p data-bind="text: fullName()"></p>
<script>
var viewModel = function () {
var self = this;
self.firstName = ko.observable( 'Ivan' );
self.lastName = ko.observable( 'M' );
self.fullName = ko.computed( function () {
return self.firstName() + ' ' + self.lastName();
} );
};
ko.applyBindings( viewModel );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment