Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  68] [ 5]  / answers: 1 / hits: 48364  / 11 Years ago, tue, february 26, 2013, 12:00:00

Today is the first day for me in Knockout . Got struck with it . Below is my first sample code using knockout.js and it shows an error .




Cannot read property 'nodeType' of null




Here is my script:`



   function ViewModel()  
{
var self = this;
self.n1 = ko.observable(10);
self.n2 = ko.observable(10);
self.n3 = ko.observable(10);
}
ko.applyBindings(new ViewModel()); `


Here is my html:



<body>
<p>Number1:<input data-bind=value:n1></input></p>
<p>Number2:<input data-bind=value:n2></input></p>
<p>Number3:<input data-bind=value:n3></input></p>
</body>


I want to know the reason for the above error and how to overcome it...


More From » html

 Answers
18

If you set up your code like this, it'll work.



<body>
<p>Number1:<input data-bind=value:n1></p>
<p>Number2:<input data-bind=value:n2></p>
<p>Number3:<input data-bind=value:n3></p>
<script src=knockout.js></script>
<script>

function ViewModel() {
var self = this;
self.n1 = ko.observable(10);
self.n2 = ko.observable(10);
self.n3 = ko.observable(10);
}

ko.applyBindings(new ViewModel()); `

</script>
</body>

[#79992] Monday, February 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
krystadesiraeo

Total Points: 493
Total Questions: 93
Total Answers: 100

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;