I am trying to use knockout and join together a first name and a last name which the user inputs. It is based off of this example: http://knockoutjs.com/examples/helloWorld.html
I tried changing the functions a bit to get a feel for knockout. The code looked good, but the output didn't change. I then tested to see if the exact code from the tutorial would work for me, but it doesn't. I'm pretty sure I'm missing something really obvious. Can someone tell me what that is?
This is my HTML:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--view-->
<head>
<meta charset="utf-8" />
<title>Testing Knockout</title>
<script src="knockoutTester.js"></script>
<script src="knockout-3.4.0.js"></script>
</head>
<body>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
</body>
</html>
This is my JS:
var ViewModel = function (first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.pureComputed(function () {
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth"));
Thanks