I have the following demo page (created with donejs):
<script type="text/stache" can-autorender id="log-template"> <can-import from="menuboard-manager/utils/logger/" /> <mbm-log></mbm-log> </script> <script src="../../../node_modules/steal/steal.js" main="can/view/autorender/"> </script>
Now if I run the following from the console, it works fine:
var lvm = $('mbm-log').viewModel(); lvm.toggle(); lvm.toggleView(); lvm.log('Hello');
How can I embed this and other calls to my component’s viewModel in the page itself either as a script or bound to buttons and other input/output widgets?
I tried putting it in the steal script (with imports from jquery and my component) but it seems that the viewModel is not yet bound to the component when the steal script runs, so the viewModel is empty and I can’t run any of my methods. If I try it in it’s own script tag, then it doesn’t have access to jquery.
I tried looking at bitballs for an example, but most of the code there is still using the old syntax and seems to be creating a template on the fly and injecting it into a div. But I already have the template created thanks to the donejs generator, but no handle to the viewModel.