I would to use compose element for real dynamic creation. I mean, I want to set the view and viewModel from string variable.
<compose view.bind=“viewHtml” view-model.bind=“viewModelCode” ></compose>
where
viewHtml="<template>apple</template>"
and
viewModelCode=“export class JSCode {}” <-!!!
Is there a way to set viewModel of compose element with javascript source code at runtime?
Can you describe a bit about your scenario? I think this is possible, but probably requires a bit of code for patching loader + and/or creating a different <compose/> element.
I have a contentWindow page. I would use it for different content. The view and view model of content comes from a restful service. (The service creates them dynamically)
So I would create ( compose ) an object/content from a restful web service source, what I want to embed into the contentWindow (with tag).
I have investigated the aurelia’s composition-engine source code and I wanted to figure out,how should I create viewModel instance from the source, but I don’t understand fully yet.
a string pointing to a module with an exported class
From the above, I think it depends on how you would want to do it, but you can tell requirejs/fusebox/systemjs (not webpack as it’s not a loader) to load module dynamically:
The following is some fake/pseudo code, as I don’t know the exact API of the loaders:
Thank you for your suggestion, I’ve made a simple “loader” for my self, because it usable with webpack too, and I use it for make a viewModel class for compose.