我遇到了一个非常奇怪的问题,在AngularJS中调用$window.print时,我只能看到左上角的日期、顶部的页面名称、右下角的页码和左下角的网址。然而,页面上没有其他内容,这非常奇怪,因为普通的页面有很多内容。
我猜想这可能与页面上的ng-view有关,但我不太确定。我会添加打印样式表,但我的问题更多的是在于没有内容可以开始样式设计。有任何想法吗?
我猜想这可能与页面上的ng-view有关,但我不太确定。我会添加打印样式表,但我的问题更多的是在于没有内容可以开始样式设计。有任何想法吗?
尝试使用(不要忘记注入服务 $timeout):
$timeout(function() {
$window.print();
})
我认为你的问题在于angular还没有完成digest循环并更新DOM。
$scope.printDiv = function(divName) {
var printContents = document.getElementById(divName).innerHTML;
var popupWin = window.open('', '_blank', 'width=300,height=300');
popupWin.document.open()
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + printContents + '</html>');
popupWin.document.close();
}