Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular4 Print Handler

Tags:

angular

I am using Angular 4. HostListener does not seem to support window.onbeforeprint event handler. For chrome I was able to add a listener for window.matchMedia('print') outside of HostListener. However this does not work for IE and Firefox. What is the best way to work with window.onbeforeprint in angular 4.

@HostListener('window:onbeforeprint',['$event'])
onBeforePrint(event){
console.log('Before print');
}

https://plnkr.co/edit/4ZdLNklitwsucH0X6Azv

like image 489
Vijay Lakshman Avatar asked Sep 07 '25 20:09

Vijay Lakshman


1 Answers

try this

import { Component, OnInit, Input, HostListener } from '@angular/core';

@HostListener('window:beforeprint',['$event'])
  onBeforePrint(event){
  console.log('Before print');
}

Instead of onbeforeprint use beforeprint

like image 140
Michael Kornelakis Avatar answered Sep 09 '25 09:09

Michael Kornelakis