Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

How can I implement a print functionality in Angular?

$
0
0

I am trying to implement a print functionality within my invoicing app, however, the print function I have only works for me once-that is, on the first click only. When I try to click again the click function is not triggered. And when I check my console.log, the following is error is thrown: ERROR TypeError: Cannot read property 'postMessage' of null

Here is what i have tried:

printInvoice() {
  const printContents = document.getElementById('print-index-invoice').innerHTML;
  const originalContents = document.body.innerHTML;
  document.body.innerHTML = printContents;
  window.print();
  document.body.innerHTML = originalContents;
}
<div class="modal fade" id="modalIndexInvoicePreview" tabindex="-1" role="dialog"><button type="submit" class="btn btn-info btn-lg mt-2 position-absolute" (click)="printInvoice()"><i class="fa fa-print icon-print"></i>Print</button><div class="modal-dialog modalContent"><div class="modal-content modalIndexInvoicePreview" id="print-index-invoice"><div class="modal-header div-logo"><img class="logo-invoice" [src]="logoUrl"><div><b>Invoice|Receipt|Attachment</b></div></div></div></div></div>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>