Basic example of knockout JS ? Below code is the basic example of knockout js .   data-bind="val

Basic example of knockout JS ? Below code is the basic example of knockout js .   data-bind="value: firstName"  helps to bind
Generic placeholder image

Mukesh R

Basic example of knockout JS ?

Below code is the basic example of knockout js .
 
data-bind="value: firstName"  helps to bind the value in the textbox to the variable firstName.  valueUpdate:'afterkeydown' is used to update the value from the textbox to variable firstName when keydown.
 
<!DOCTYPE html>
<head>
   <title>Basic Example of Knockout JS</title>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js" type="text/javascript"></script>
</head>

<body>

   <p>Enter name: <input data-bind="value: firstName, valueUpdate:'afterkeydown'" /></p>
   <p>  <strong data-bind="text: calculatedString">Data</strong></p>
   
   <script>
   
   function AppDataViewModel() {
       this.firstName = ko.observable("Enter First String");
       

       this.calculatedString = ko.computed(function() {
	     return "Name of the person is " + this.firstName();
    }, this);
   }
   ko.applyBindings(new AppDataViewModel());
   
   </script>
   
</body>
</html>