I am trying to dynamically compose a view, but at run time i get the error Error: Unable to find module with ID: app/components/customers/customer-type-view-converter.html.
I'm using webpack.
Here's the view converter that i'm using
import {PLATFORM} from 'aurelia-framework';
export class CustomerTypeViewConverter {
toView(type: string) {
return type == 'LEGAL' ? PLATFORM.moduleName("createLEGALcustomer.html") : PLATFORM.moduleName("createNATURALcustomer.html")
}
}
here's the template that calls the convertor
<template>
<require from="./customer-type-view-converter"></require>
<ux-dialog style="min-width:500px">
<ux-dialog-header>
<h1>Create Customer</h1>
</ux-dialog-header>
<ux-dialog-body>
<form class="form-horizontal">
<div class="form-group">
<label for="name" class="col-sm-4 control-label">Customer Type:</label>
<div class="col-sm-8">
<select value.bind="customer.customerType">
<option value="NATURAL">Person</option>
<option value="LEGAL">Company or Organisation</option>
</select>
</div>
</div>
<compose view.bind="customer.customerType | customerTypeView"></compose>
</form>
</ux-dialog-body>
<ux-dialog-footer>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="submit()">Ok</button>
</ux-dialog-footer>
</ux-dialog>
</template>
Two issues here. Firstly. the class name should have been CustomerTypeView Value Converter in order for Aurelia to reconise it as a special class that doen't require a view.
And in the Value converter itself the html files should have been prefixed with ./
so webpack could find them
updated value converter below
import {PLATFORM } from 'aurelia-framework';
export class CustomerTypeViewValueConverter {
toView(type: string) {
return type == 'LEGAL' ? PLATFORM.moduleName("./createLEGALcustomer.html") : PLATFORM.moduleName("./createNATURALcustomer.html")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.