我在我的应用程序中使用角度2 . 我有一个名为test.component.ts的组件,此组件的templateurl是test.component.html,styleurl是test.component.css . 我在test.component.html页面上有一个打印按钮 . 我需要使用打印按钮在同一页面(test.component.html)上打印名为'print-data'的div的内容 . div'print-data'使用test.component.css文件中定义的css类 . 我可以在浏览器上看到应用的css,但是当我点击打印按钮时,打印窗口会在div中显示文本而不应用任何css . 类型脚本代码是:
var mywindow = window.open('', 'PRINT', 'height=800,width=800');
let printdiv = document.getElementById('print-data');
mywindow.document.write(printdiv.innerHTML);
mywindow.focus();
mywindow.print();
当我尝试将链接附加到test.component.css时,如下所示:
var mywindow = window.open('', 'PRINT', 'height=800,width=800');
let printdiv = document.getElementById('print-data');
mywindow.document.write(`<html><head><link rel="stylesheet"
type="text/css" href="test.component.css" /></head><body>`);
mywindow.document.write(printdiv.innerHTML);
mywindow.document.write('</body></html>');
mywindow.focus();
mywindow.print();
在打印窗口控制台上,它显示“无法加载资源:服务器响应状态为404(未找到)test.component.css” .
我无法在打印窗口内容中附加我的test.component.css文件类 . 请帮帮我 .
1 回答