Shinigamiyuu
Shinigamiyuu

Reputation: 45

How do i initialize knockout into my html(index)

I dont know why its not working correctly as it supposed to do. (im new to this things) This is my html index:

<!DOCTYPE html>
<head>
</head>

<body>

<p>First name: <strong data-bind = "text: firstName"></strong></p>
<p>Last name: <strong data-bind = "text: lastName"></strong></p>

<script src="js/myscripts.js"></script>
<script src="js/knockout-3.3.0.js"></script>

</body>

Below is my js code in file named "myscripts":

function AppViewModel() {
    this.firstName = "Bert";
    this.lastName = "Bertington";
}


ko.applyBindings(new AppViewModel());

This shows only this in my browser:

First name:

Last name: 

but should be:

First name: Bert

Last name: Bertington

In folder named "js" i got 2 files named: myscripts.js and knockout-3.3.0.js

Upvotes: 2

Views: 65

Answers (1)

awj
awj

Reputation: 7949

You need to load the knockout script before you load your own script which references knockout.

<script src="js/knockout-3.3.0.js"></script>
<script src="js/myscripts.js"></script>

Upvotes: 1

Related Questions