Filters - jasperjs/jasper-application GitHub Wiki

Filters formats the value of an expression for display to the user. They can be used in view templates, components or services and it is easy to define your own filter. You can read more about AngularJS filters at developer guide.

To create filter type:

yo jasper:filter <AREANAME> <FILTERNAME>

For instance:

yo jasper:filter shop currency

New filter will created in filter folder in specified area.

Each filter represented as function that receive any input value and must return any string representation of this value.

module spa.shop.filters {
    // you can use this filter like: {{ someExpression | currency }}
    export class Currency {
        // you may inject any services here
        static $inject = []; 

        constructor() {
            return (source: number) => {
                // if not a number return empty string
                if (!source || typeof source !== "number") {
                    return '';
                } else {
                    return '$' + source; // format the price
                }
            }
        }
    }
}

After that you can format values, using this filter in your templates:

<p>
   {{ good.price | currency }}
</p>
⚠️ **GitHub.com Fallback** ⚠️