JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
How do I call the component view model foo function outside of the context of the foo element/template?
<br />
<br />
<foo></foo>
<template id="component-foo">Foo component</template>
JavaScript
ko.components.register("foo", {
viewModel: FooComponentViewModel,
template: {
element: "component-foo"
}
});
function FooComponentViewModel(params) {
this.Foo = function () {
alert("bar");
};
}
var ViewModel = function () {
// empty
};
var vm = ViewModel();
ko.applyBindings();