vai*_*ani 5 javascript angular
我正在使用angualr 2。
我正在尝试打印html div。
这是我的代码
<div id="print-section">
// Html code
</div>
<button (click)="open()">print</button>
print(): void {
let printContents, popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<title>Print tab</title>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
);
popupWin.document.close();
}
Run Code Online (Sandbox Code Playgroud)
这是我的open()
open(){
//I called Api using service
let scope=this;
setTimeout(function() { scope.print(); }, 3000);
}
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误
错误TypeError:无法读取null的属性“文档”。
我该如何解决这个问题?
| 归档时间: |
|
| 查看次数: |
11478 次 |
| 最近记录: |