I know there are better patterns but in this case there\'s some legacy code that we\'d like to move to a view. This html has a
You could use a custom KnockOut binding for this.
Here's a really simple binding - keep in mind this is just an idea:
ko.bindingHandlers.script = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var scriptName = ko.utils.unwrapObservable(valueAccessor());
$(element).html("");
}
};
In your view (.html file):
I tested this, and I found that the script is indeed injected, parsed, and executed, but it doesn't stay loaded in the DOM. That may or may not be an issue for you.
Seems that stripping the tags may be a Durandal-specific thing. I haven't figured out the cause yet, but I'll update if I get a chance to dig into it.