I am trying to inject DecimalPipe
to my custom pipe as described in this answer.
here is the code:
@Pipe({name: 'irc'})
export class IRCurrencyPipe implements PipeTransform {
constructor(private decimalPipe: DecimalPipe) {}
transform(value: string | number, type: string = 'rial') {
value = Number(value);
if (isNaN(value)) { throw new Error(`${value} is not a acceptable number`); }
return this.decimalPipe.transform(value, '1.0-0') + ' ریال';
}
}
But I get TypeError: Cannot read property 'transform' of undefined
error when running tests from this code.
I also tried extending the DecimalPipe
as suggested in this answer
:
@Pipe({name: 'irc'})
export class IRCurrencyPipe extends DecimalPipe implements PipeTransform {
transform(value: string | number, type: string = 'rial') {
value = Number(value);
if (isNaN(value)) { throw new Error(`${value} is not a acceptable number`); }
return super.transform(value, '1.0-0') + ' ریال';
}
}
But I get: Error: InvalidPipeArgument: 'Cannot read property 'toLowerCase' of undefined' for pipe 'DecimalPipe'
in this case.
Is there a working solution to using one of the built-in pipes in angular to a custom pipe?