peerigon / angular-expressions

Angular expressions as standalone module
The Unlicense
95 stars 23 forks source link

Static filter params #9

Closed ranode closed 6 years ago

ranode commented 7 years ago

Is there a way to use a string as filter param? Eg. a date format string. This could just be a static string value, without needing to evaluate against scope.

edi9999 commented 7 years ago

Yes you can.

For example :

expressions.filters.currency = function (input, currency, digits) {
    input = input.toFixed(digits);

    if (currency === "EUR") {
        return input + "€";
    }
    return input + "$";
};

evaluate = compile("1.2345 | currency:'EUR'");
expect(evaluate({
    selectedCurrency: "EUR"
})).to.equal("1.23€");