Dos filtros nuevos, para monedas y porcentajes

This commit is contained in:
Javi Gallego 2018-10-16 13:57:14 +02:00
parent 67bd3d96d3
commit 4000926c74
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import ngModule from '../module';
/**
* Override angular currency formats a number adding symbol after value.
*
* @return {String} The formated number
*/
export default function currency() {
return function(input, symbol, fractionSize) {
if (input == null || input === '')
return null;
if (typeof input == 'number' && fractionSize)
input = input.toFixed(fractionSize);
return `${input} ${symbol}`;
};
}
ngModule.filter('currency', currency);

View File

@ -0,0 +1,15 @@
import ngModule from '../module';
/**
* Formats a number multiplying by 100 and adding character %.
*
* @return {String} The formated number
*/
export default function percentage() {
return function(input) {
if (input == null || input === '')
return null;
return input * 100 + ' %';
};
}
ngModule.filter('percentage', percentage);