KnockoutJs does not work

2

Code:

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='js/knockout-3.2.0.js'></script>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>

<script type="text/javascript">
function AppViewModel() {
    this.firstName = "Bert";
    this.lastName = "Bertington";
}


ko.applyBindings(new AppViewModel());

</script>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>

</body>

</html>
    
asked by anonymous 03.12.2014 / 20:14

1 answer

2

Put ko.applyBindings at the bottom of the page or inside the

$ (function () {

});

From JQUERY.

In your case, do it this way.

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://knockoutjs.com/downloads/knockout-3.2.0.js'></script>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>


<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName"/></p>

</body>

</html>

<script type="text/javascript">

function AppViewModel() {
    this.firstName = "Paulo";
    this.lastName = "Sousa";
}


ko.applyBindings(new AppViewModel());

</script>
    
03.12.2014 / 20:30