Home > database >  Call Window.Print() after page fully load with HTML and CSS in angular
Call Window.Print() after page fully load with HTML and CSS in angular

Time:10-12

I am using below code with setTimeout but this is hack. I want to call window.print() once page fully loaded with html and css. Kindly suggest better solutions.

const WindowPrt = window.open(url, '_blank', 'left=0,top=0,width=900,height=900,toolbar=0,scrollbars=0,status=0');
    
setTimeout(() => {
      WindowPrt.focus();
      WindowPrt.print();
      WindowPrt.close();
    }, 10000);

CodePudding user response:

When the page loads, you would need to implement lifecycle hook, like ngOnInit,ngAfterViewInit to be specific inside that particular component level. To learn more about this . see the examples in the below link

https://angular.io/guide/lifecycle-hooks

CodePudding user response:

Angular has a specific function that called when the view is fully initialized. it's called ngAfterViewInit check this link for more docs

  • Related