Can I create non-empty Knockout components that use the child markup within them?
An example would be a component for displaying a modal dialog, such as:
<modal-dialog>
<h1>Are you sure you want to quit?</h1>
<p>All unsaved changes will be lost</p>
</modal-dialog>
Which together with the component template:
<div class="modal">
<header>
<button>X</button>
</header>
<section>
<!-- component child content somehow goes here -->
</section>
<footer>
<button>Cancel</button>
<button>Confirm</button>
</footer>
</div>
Outputs:
<div class="modal">
<header>
<button>X</button>
</header>
<section>
<h1>Are you sure you want to quit?</h1>
<p>All unsaved changes will be lost</p>
</section>
<footer>
<button>Cancel</button>
<button>Confirm</button>
</footer>
</div>
It's impossible in 3.2, however it would be possible in next version, see this commit and this test.
For now to you have to pass parameters to component via
paramsproperty Define your component to expectcontentparameter:Pass content parameter via
paramspropertySee fiddle
In new version you can use
$componentTemplateNodesUsage in parent component:
P.S. You can build last version of knockout manually to use code above.