Search code examples
javascriptviewmodelaureliaconverters

Aurelia, converter use inside view model


Using Aurelia, i'm trying to use a converter inside a view model. But I don't know how to do it or if it's even possible.

With AngularJS, for example :
inside a view

<span>{{ 'hello' | uppercase }}</span>

inside a controller

$filter('uppercase')('hello');

With Aurelia
inside a view

<span>${ 'hello' | uppercase }</span>

inside a viewmodel

?????????

Solution

  • Ok so, this is simple.
    As our converters are classes, we just have to call the method toView from an instance.

    import { UppercaseValueConverter } from './converters';
    
    const convertedValue = new UppercaseValueConverter().toView('Hello');
    

    In my case I was a little bit lost, because I use a library and can't import the converter class directly.