Im doing the Introduction tutorial for Knockout, the second part of the tutorial is about observables, I have the following code on my .ts (later .js):
/// <reference path="../typings/index.d.ts" />
$(document).ready(function () {
ko.applyBindings(new ViewModel());
});
class Person {
firstName: string;
lastName: string;
constructor(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName
}
}
var ViewModel = function () {
var person = new Person('MyName', 'MyLastName');
this.person = person;
this.person = ko.observable(person.firstName);
this.person = ko.observable(person.lastName);
};
and I have the following in my cshtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="~/bower_components/jquery/dist/jquery.js"></script>
<script src="~/bower_components/knockout/dist/knockout.js"></script>
<script src="~/Scripts/greeter.js"></script>
<title>Index</title>
</head>
<body>
<div>
<p>FirstName: </p> <p data-bind="text: person.firstName"></p>
<p>LastName: </p> <p data-bind="text: person.lastName"></p>
<p>First name: <input data-bind="value: person.firstName" /></p>
<p>Last name: <input data-bind="value: person.lastName" /></p>
</div>
</body>
</html>
When I run the web app, instead of showing "MyName" and "MyLastName" on my <p> tags it shows nothing and when I write in my <input> it does not show anything in my <p> tags.
So the question is, it is possible to change attributes of a class or I need it change only variables?