Created
September 28, 2016 22:20
-
-
Save jpolvora/3712241510e1b1023fbb00d0285dedf8 to your computer and use it in GitHub Desktop.
SystemJS Knockout JS Module Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, could you show me what goes into the file 'js2/mainViewModel.js' for this to work? Thanks.