I have an app where I'm dynamically loading content into parts of the page. Sometimes the code has data-bind
attributes, which seem to be getting ignored by KnockOutJS.
HTML:
<div data-bind="html: code">
this text is replaced by the JavaScript
</div>
function AppView() {
var self = this;
// This sets the code
self.code = ko.observable('<div>this shouldnt show</div>');
self.stuff = ko.observable('this should show');
}
var app = new AppView();
ko.applyBindings(app);
// Later we override the code. We're setting an observable, so the app should notice.
app.code('<div data-bind="text: stuff">this shouldnt show either</div>');
Esentially, I need the handlers to be initialized. Do I need to remove all bindings, and reapply?