Dynamically loaded Components parameters

156 views
Skip to first unread message

Dustin Bertsch

unread,
May 21, 2015, 2:44:34 PM5/21/15
to knock...@googlegroups.com
I'm experimenting with Knockout's components, and have run into a situation where I seem to be up against a wall. 

demo: jsfiddle

When loading a component on demand (via requirejs), is there a way to bind an existing component observable ('the parent') to the loaded component('child') as the documentation states here: http://knockoutjs.com/documentation/component-custom-elements.html#communication-between-parent-and-child-components

Dustin Bertsch

unread,
May 21, 2015, 7:16:25 PM5/21/15
to knock...@googlegroups.com
On further trial and error, I find that the context of the parent view model will not be available to dynamically added elements. Which is why binding to the dynamic element is possible, while being nested in a previously bound element. (parent)

I've decided to use knockout-postbox subscriptions for this type of two way communication, unless needing to pass a literal. 

If anyone knows or could point me to a example of loading nested components on demand, I'd appreciate it.

Noirabys

unread,
May 22, 2015, 2:28:34 AM5/22/15
to knock...@googlegroups.com
hi,

have a look at:

i've successfully implemented a asynchronous module loading based on that examples.
you can than easily use components in components etc.

best regards,
  noirabys

Dustin Bertsch

unread,
May 22, 2015, 10:49:20 AM5/22/15
to knock...@googlegroups.com
I will certainly look into custom loaders. 



Thanks Noiraby.

Michael Best

unread,
May 22, 2015, 10:05:47 PM5/22/15
to knock...@googlegroups.com
I was able to make your example work by using ko.contextFor, described here: http://knockoutjs.com/documentation/unobtrusive-event-handling.html


-- Michael

Dustin Bertsch

unread,
May 26, 2015, 12:04:17 PM5/26/15
to knock...@googlegroups.com
Thank you Michael,

Your help is most appreciated.
Reply all
Reply to author
Forward
0 new messages