user3488885
user3488885

Reputation: 67

Starting with knockoutjs

I'm trying to start a webpage with knockou.js I'm trying to follow the instruction on the web and create very simple page, but for some reason i don't get the binding... maybe i miss a definiation or something like that? can anybody help with that?

That my page:

<html class="rtl">
    <head>
        <title>changeup - קבל שער</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="format-detection" content="telephone=no">
        <script type='text/javascript' src='bower_components/knockout.js/knockout.js'></script>
    </head>
    <body cz-shortcut-listen="true">

    Today's message is: <span data-bind="text: myMessage"></span>


    <script type="text/javascript">
        var viewModel = {
            myMessage: ko.observable() // Initially blank
        };
        viewModel.myMessage("Hello, world!"); // Text appears

    </script>



    </body>
</html>

but the only think i get on my browser is: "Today's message is:"

Upvotes: 0

Views: 59

Answers (1)

Major Byte
Major Byte

Reputation: 4101

Read through the documentation under the subject Activating Knockout, you have to apply the bindings as well, add:

ko.applyBindings(viewModel); 

after viewModel.myMessage("Hello, world!");

Upvotes: 3

Related Questions