Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Pen by Rahul P Nath.
<button onClick="updateName()" >Update Name</button></div>
<label data-bind="text: Name"></label>
// View Model
// Having the properties as observables is similar to having INotifyPropertyChanged implemented
// and raising the propertychanged event for the property in the setter method.
var personVM = {
Name: ko.observable("Rahul"),
Age: ko.observable(50)
// Bind the View Model to the document
// This is similar to binding to DataContext in XAML
// This is a function that will toggle the name, which will trigger a UI refresh
function updateName(){
if(personVM.Name() === "Rahul"){
personVM.Name("Rahul Nath");
else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.