Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting "Cannot read property 'nodeType' of null" when calling ko.applyBindings
    text
    copied!<p>I have this knockout code:</p> <pre><code>function Task(data) { this.title = ko.observable(data.title); this.isDone = ko.observable(data.isDone); } function TaskListViewModel() { // Data var self = this; self.tasks = ko.observableArray([]); self.newTaskText = ko.observable(); self.incompleteTasks = ko.computed(function() { return ko.utils.arrayFilter(self.tasks(), function(task) { return !task.isDone() }); }); // Operations self.addTask = function() { self.tasks.push(new Task({ title: this.newTaskText() })); self.newTaskText(""); }; self.removeTask = function(task) { self.tasks.remove(task) }; } ko.applyBindings(new TaskListViewModel()); </code></pre> <p>This html:</p> <pre class="lang-html prettyprint-override"><code>&lt;head&gt; &lt;script type="text/javascript" src="jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="knockout-2.0.0.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;Tasks&lt;/h3&gt; &lt;form data-bind="submit: addTask"&gt; Add task: &lt;input data-bind="value: newTaskText" placeholder="What needs to be done?" /&gt; &lt;button type="submit"&gt;Add&lt;/button&gt; &lt;/form&gt; &lt;ul data-bind="foreach: tasks, visible: tasks().length &gt; 0"&gt; &lt;li&gt; &lt;input type="checkbox" data-bind="checked: isDone" /&gt; &lt;input data-bind="value: title, disable: isDone" /&gt; &lt;a href="#" data-bind="click: $parent.removeTask"&gt;Delete&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; You have &lt;b data-bind="text: incompleteTasks().length"&gt;&amp;nbsp;&lt;/b&gt; incomplete task(s) &lt;span data-bind="visible: incompleteTasks().length == 0"&gt; - it's beer time!&lt;/span&gt; &lt;/body&gt; </code></pre> <p>The example is the same as the one found on the Knockout website, but when I run it, it returns this message on Chrome Fire Bug:</p> <blockquote> <p>Uncaught TypeError: Cannot read property 'nodeType' of null</p> </blockquote> <p>This one is related to the knockout file and to this line of my script:</p> <pre><code>ko.applyBindings(new TaskListViewModel()); </code></pre> <p>And this error is pointing to this line (1766) on knockout:</p> <pre><code>var isElement = (nodeVerified.nodeType == 1); </code></pre> <p>What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload