'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 1:[1]
In your viewmodel add the following code:
export class UppercaseValueConverter {
toView(value) {
return value?.toUpperCase();
}
}
and then in your view:
<h1>${message | uppercase}</h1>
See a working example.
You can also add the value converter to the global resources section of your app to share it among all views.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cristián Ormazábal |
