Attempting the most basic example of Knockout.js possible on their documentation page:
http://knockoutjs.com/documentation/observables.html
Looks like I have everything setup like the documentation is asking for, and I’m not getting any errors on the page, but the span should display the binding of “personName” – which is ‘Bob’.
However, when I run the page all that appears is “The name is”. Bob is nowhere to be found.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Knockout Practice</title>
<script type='text/javascript' src='javascript/jquery-1.6.4.js'></script>
<script type='text/javascript' src='javascript/jquery-tmpl.js'></script>
<script type='text/javascript' src='javascript/knockout-1.2.1.js'></script>
<script type="text/javascript">
var myViewModel = {
personName: 'Bob',
personAge: 123
};
ko.applyBindings(myViewModel);
</script>
</head>
<body>
The name is <span data-bind="text: personName"></span>
</body>
</html>
Is there something missing in the documentation, or am I missing something?
You need to change where the script loads.
Putting the script block at the end of HTML document does indeed show
for
<span data-bind="text: personName">Bob</span>