Reputation: 845
I am new to knockout using knockout2.1.0. I have an external java script file, but it is not called in my html file. I can not understand.
I have added the following in my html file
<script src="Scripts/TestJavascript.js"></script>
JS File
///<reference path="~/Scripts/jquery-1.8.1.min.js">
///<reference path="~/Scripts/knockout-2.1.0.debug.js">
$(function AppViewModel() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
return this.firstName() + " " + this.lastName();
}, this);
})
ko.applyBindings(new AppViewModel());
thanks.
Upvotes: 0
Views: 149
Reputation: 7591
this code must appear either after the bound html, or within a document ready event (jquery)
function AppViewModel() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new AppViewModel());
Upvotes: 1
Reputation: 191037
You aren't creating a ViewModel. You are passing it to jquery.
Try
var AppViewModel = function() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
return this.firstName() + " " + this.lastName();
}, this);
})
ko.applyBindings(new AppViewModel());
Upvotes: 5