Should we wait for the DOM to load before calling ko.applyBindings

According to the header, do I have to wait for the DOM to load before calling ko.applyBindings or will Knockout handle this automatically?

Ie - I'm just safe:

 <script> (function() { var model = new my.Model(); ko.applyBindings(model); })(); </script> 
+6
source share
1 answer

No KO does not handle this automatically (therefore, the self-start function will work only at the bottom of your page), you need to wait for the DOM to load with a call to ko.applyBindings .

From the documentation :

To activate Knockout, add the following line to the <script> block:

ko.applyBindings(myViewModel);

You can put a script block at the bottom of your HTML document, or you can put it at the top and wrap the content in a DOM-ready handler, such as the jQuerys $ function.

+8
source

All Articles