You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you do it from the html/head the body isn't present yet and you get a null reference exception from (see a line below):
functionapplyBindingsToNodeAndDescendantsInternal(bindingContext,nodeVerified,bindingContextMayDifferFromDomParentElement){varshouldBindDescendants=true;// Perf optimisation: Apply bindings only if...// (1) We need to store the binding context on this node (because it may differ from the DOM parent node's binding context)// Note that we can't store binding contexts on non-elements (e.g., text nodes), as IE doesn't allow expando properties for those// (2) It might have bindings (e.g., it has a data-bind attribute, or it's a marker for a containerless template)varisElement=(nodeVerified.nodeType===1);<---***HERE***/* ... */}
The text was updated successfully, but these errors were encountered:
I think it's kinda outside of the scope of Knockout. It should be specified in the docs if it isn't already, but I don't think a code change would be positive.
Most people do something like this if they include jQuery.
$(function(){ko.applyBindings(viewModel);});
Personally, I put this in the bottom of my HTML file, so the order of files doesn't matter, and they can be loaded in the head, end of body, middle of body.. wherever.
Everything you guys have said makes sense, my point is that KO needs an additional check for null and an error message that makes sense at applying bindings.
A simple code change, to move rootNode = rootNode || window.document.body before the code that checks rootNode could help with this. At least, then, you'd get a meaningful exception.
My bad that instead of
I did
if you do it from the html/head the body isn't present yet and you get a null reference exception from (see a line below):
The text was updated successfully, but these errors were encountered: