I wish to make a Durandal custom dialog that adds a window frame with title and footer around an existing composable viewmodel.
I have made a customModal.html template
<div class="messageBox">
<div class="modal-header">
<h3 data-bind="text: title"></h3>
</div>
<div class="modal-body">
<!--ko compose: { model: model, template: view }-->
<!--/ko-->
</div>
<div class="modal-footer" data-bind="foreach: options">
<button class="btn" data-bind="click: function () { $parent.selectOption($data); }, text: $data, css: { 'btn-primary': $index() == 0, autofocus: $index() == 0 }"></button>
</div>
</div>
As you can see I wish to compose a viewmodel within the body of the customModal template. This is so that the viewmodel passed in is not tied to a modal display but can easily use one.
I have made a customModal.js model like this:
define(['plugins/dialog'], function (dialog) {
var CustomModal = function (title, model, view, options) {
this.title = title;
this.model = model;
this.view = view;
this.options = options;
};
CustomModal.prototype.selectOption = function (dialogResult) {
dialog.close(this, dialogResult);
};
return CustomModal;
});
But when I try and use it the compose binding searches for the template '.html' and fails.
Am I missing something here? And is this really the best way to do this?
Thanks.