Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can my Knockout/RequireJS widget bind to the correct context when used in a site that also uses Knockout?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThis is a challenging one. My thought at the moment would be to wrap your widget in a container that has a binding like I described [here](http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html). Then, when your widget script loads, add the custom binding to your instance of KO and see if window.ko exists and add it there as well. The only remaining issue would be if you are using multiple KO versions through require.js or if there is a timing issue from when `ko.applyBindings` is called and when your module is loaded. Would be good if we added a `stopBindings` like binding to KO core.
      singulars
    2. COYeah, that was the approach I was taking but I'm not 100% happy about having to divine the location of the outer container's instance of KO.
      singulars
    3. CORight, currently I can't think of a better solution that doesn't also have drawbacks. For example, you could use a [custom binding provider](http://www.knockmeout.net/2011/09/ko-13-preview-part-2-custom-binding.html) that doesn't use `data-bind` and uses `spig-bind` (or whatever), but that might mess up the existing instance of KO. It could support both attributes, so that in the case that your page and your widget use the same instance of KO, you will still be okay. Still not great, just another thought.
      singulars
 

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