I am witnessing a strange behavior of value converters when used from a custom element.
This is a simple app:
<import from="./test-element"></import>
<import from="./test-converter"></import>
<div class="message">${message}</div>
<test-element></test-element>
<div textcontent.bind="'hello from my-app' | testConverter"></div>
TestElement:
import { customElement, ICustomElementViewModel } from '@aurelia/runtime-html';
import template from './test-element.html';
@customElement({
name: 'test-element',
template: template,
})
export class TestElement implements ICustomElementViewModel {
constructor() {}
}
<import from="./test-converter"></import>
<p>test element</p>
<!-- <div textcontent.bind="'hello from test-element' | testConverter"></div> -->
And TestConverter:
import { valueConverter } from '@aurelia/runtime-html';
@valueConverter('testConverter')
export class TestConverter {
toView(value: string) {
return value.toUpperCase();
}
}
This code creates the following output:
Hello World!
test element
HELLO FROM MY-APP
But when I uncomment value converter usage in TestElement, the page stops rendering the TestElement at all!
Hello World!
HELLO FROM MY-APP
Am I missing something? I started to investigate this issue because in my code I have a similar issue, when value converter works from some page when imported locally via <import from>
tag, but cannot be found from the custom element inside that page with error message “[DEV:aurelia] Cannot retrieve value converter with name testConverter” but works ok when registered globally in main.ts.