I'm trying to create a knockout component and load its template from a file like so:
function ordersViewModel(){
//whatever
}
function equipmentViewModel(){
//whatever
}
ko.components.register('compact-view', {
viewModel: ordersViewModel,
template: {require: '../views/orders/compactTable.html'},
synchronous: true
});
var MasterModel = function(){
this.orders = new ordersViewModel(),
this.equipment = new equipmentViewModel();
};
var mm = new MasterModel();
And I'm getting the following error:
Failed to load resource: the server responded with a status of 404 (Not Found) https://localhost/views/orders/compactTable.html.js
It seems it is looking for the .js as detailed in the docs:
For this to work, the files
files/component-like-widget.js
andfiles/component-like-widget.html
need to exist.
Isn't there a way to use a component without having to separate the viewmodel in another file?
I'm using a MasterModel to be able to call other viewmodel functions from any other viewmodel, and probably separating the ordersViewModel
in another file will make things more difficult.