Below you will find my Angular project's pdfService
. I am facing an issue where calling the this.formatter()
method inside myPDF is not functioning properly.
export class pdfService {
formatter(value: number): string {
return new Intl.NumberFormat('en-IN', {style: 'decimal', currency: 'INR'}).format(value);
}
myPDF() {
const doc = new jsPDF();
doc.text('Values', 10, 25, 'left');
doc.text(this.formatter(1000), 10, 25, 'left');
doc.text(this.formatter(10000), 10, 35, 'left');
window.open(doc.output('bloburl'));
}
}
When I include the method within myPDF, it works as expected. See code below:
function formatter(value: number): string {
return new Intl.NumberFormat('en-IN', {style: 'decimal', currency: 'INR'}).format(value);
}
I require the use of the formatter
method in multiple PDF methods. Where should I place it?
Note: Repeating the formatter
method in all PDF methods is one possible solution but not the ideal approach.