ngx-print
ngx-print copied to clipboard
How to call ngx-print from a function
I would like to call ngx-print from a function in .ts file
I have a button that calls the server, when data gathering is complete, then, print.
How do it do this?
Use a template reference in HTML "#print". Add a click event on any other element and hide the button where the template reference is set => invisible button, so you can use any element you want to trigger the print, as only button works.
<div (click)="triggerPrint();">
<span>Print</span>
</div>
<button #print printTitle="report" printSectionId="content-section" ngxPrint hidden="true" [useExistingCss]="true"
></button>
In TS file use the ViewChild to add the template reference and use it in your triggerPrint method
@ViewChild("print") print!: ElementRef;
public triggerPrint(): void {
this.print.nativeElement.click();
}
Does that work for you @thelionleo ?
This solution works flawlessly. It will also work when the the "content-section" is set to display: none.