Skip to content

Instantly share code, notes, and snippets.

@MatthewVita
Last active August 29, 2015 13:57
Show Gist options
  • Save MatthewVita/9586826 to your computer and use it in GitHub Desktop.
Save MatthewVita/9586826 to your computer and use it in GitHub Desktop.
KOTemplateLoader.js - Loader that easily renders external Knockout.js templates [jQuery dependency]
/*
* @desc: loads an external
* HTML Knockout.js template
* file, places it in the DOM,
* and applies the KO bindings
*
* @param: tmplFile - the template
* file
*
* @param: targetElem - the target
* element's id or class
*
* @param: viewModelInst - instance of
* the relative view model object
*/
function loadExternalKoTemplate(tmplFile, targetElem, viewModelInst) {
$.get(tmplFile)
.success(function(data) {
$(targetElem).html(data);
ko.applyBindings(viewModelInst, $(targetElem)[0]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment