Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Created September 28, 2016 22:20
Show Gist options
  • Save jpolvora/3712241510e1b1023fbb00d0285dedf8 to your computer and use it in GitHub Desktop.
Save jpolvora/3712241510e1b1023fbb00d0285dedf8 to your computer and use it in GitHub Desktop.
SystemJS Knockout JS Module Loader
var systemJsLoader = {
loadComponent: function (name, templateConfig, callback) {
if (templateConfig.systemjs) {
SystemJS.import(templateConfig.systemjs)
.then(function (viewModelCtor) {
callback({
createViewModel: function (params, componentInfo) {
return viewModelCtor.viewModel(params, componentInfo);
},
template: ko.utils.parseHtmlFragment(viewModelCtor.template)
});
})
.catch(function (error) {
callback(null);
});
}
}
};
ko.components.loaders.unshift(systemJsLoader);
ko.components.register('app-view', { systemjs: 'js2/mainViewModel.js' });
@fredespi
Copy link

hi, could you show me what goes into the file 'js2/mainViewModel.js' for this to work? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment