Having Trouble Binding a Knockout.js ViewModel to MVC
Despite attempting to follow multiple tutorials, none of them seem to be working for me. I have not encountered any errors while building the app, but the results are not as expected.
Here is my TS file:
/// <reference path="../typings/knockout/knockout.d.ts" />
/// <reference path="../typings/jquery/jquery.d.ts" />
export module HopCRM {
export class ContactViewModel {
text: string = "Test";
public test: KnockoutObservable<string>;
constructor() {
console.log("hello")
this.test = ko.observable("Test testing testing")
}
}
}
And here is my CSHTML:
<h2 data-bind="text: test">Waiting for viewModel</h2>
<script src="~/Scripts/Typescript/ContactViewModel.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1 /jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js"></script>
<script type="text/javascript">
var viewModel;
(function () {
viewModel = new HopCRM.ContactViewModel();
ko.applyBindings(viewModel);
});
</script>
I was expecting a binding from 'public test' or at least a simple console.log statement to appear.