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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With