2017-09-15 99 views
0

我正在使用Angular 4. HostListener似乎不支持window.onbeforeprint事件处理程序。对于chrome,我能够在HostListener之外为window.matchMedia('print')添加一个侦听器。但是这对IE和Firefox不起作用。什么是window.onbeforeprint工作在角4Angular4打印处理程序

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

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

回答

1

试试这个

import { Component, OnInit, Input, HostListener } from '@angular/core'; 
.... 
.... 
@HostListener('window:beforeprint',['$event']) 
onBeforePrint(event){ 
console.log('Before print'); 
} 

而是 'onbeforeprint' 使用 'beforeprint'

的最佳途径