Question

The HTML below is injected into my site on an ajax call, but the template is not being picked up. Is there something I need to do to register it?

Unable to parse binding attribute. Message:
ReferenceError: answerTmpl is not defined;
Attribute value: template: { name: answerTmpl, foreach: answers }

Dynamic HTML:

<script id="answerTmpl" type="text/html">
    <div>
      <span></span>  <input type="checkbox" name="Answer" />
    </div>
</script>

<div id="answers" data-bind="template: { name: answerTmpl, foreach: answers }"></div>

Corresponding JS:

ko.applyBindingsToNode(document.getElementById('answers'));
Was it helpful?

Solution

You need to put your template name in quotes, so name: 'answerTmpl'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top