Knockout JS [Hello World]

Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates. The underlying principles are therefore: a clear separation between domain data, view components and data to be displayed.
What is Model?
Model is your business entity like User,Customer objects which contains property.
What is ViewModel:
Viewmodel looks like Model but it contains behavior
Let's create a simple hello world example using knockout.js.Create a html file named index.html and add following code
In the above code,first I have added refrence of knockout.js and then created two html controls input and span.Notice the markup on line 8 and 9 We are using a new attribute: data-bind.
data-bind is knockout syntax for binding viewmodel property to view.
On line 10 to 14 I have created a simple viewmodel which have one singal property message with default value "Hello World".
On line 15 I am attaching viewmodel to view 

Post a Comment


Close Menu