我有一个Jade文件html
function simpleArrayCompare($a,$b){
if( count($a)===count($b) ){
foreach($a as $key=>$value){
if( $a[$key] != $b[$key] ){ return false; }// [!= / !==] for equal/identical
}
}
return true;
}
我有我的控制器文件
include ../../../public/UI-Master-Layout/Jade/userMenu.jade
include ../../../public/UI-Master-Layout/Jade/footer.jade
include ../../mixinHelp.jade
div.container.cstm-panel-heading(ng-controller="studentInformationCtrl")
.container
.row
.col-lg-12
div#printableArea
table.cstm-panel-heading.darkgray(align='center')
colgroup
col(width="50%")
col(width="50%")
tbody
tr
td(colspan='2' align='center') Student Information
tr
td First Name
td {{student.firstName}}
tr
td Last Name
td {{student.lastName}}
button.btn.btn-info.pull-right(type='button',ng-click="printDiv('printableArea')") Print
如果我只是执行$ window.print(),我会打印出值。但我正在尝试打印选定的div printableArea。我错过了什么
答案 0 :(得分:0)
经过一番搜索,我可以使用jQuery解决它
$scope.printDiv = function(divName) {
var html = "";
$('link').each(function() {
if ($(this).attr('rel').indexOf('stylesheet') !=-1) {
html += '<link rel="stylesheet" href="'+$(this).attr("href")+'" />';
}
});
html += '<body onload="window.focus(); window.print()">' + $("#" + divName).html()+'</body>';
var w = window.open("","print");
if (w) { w.document.write(html); w.document.close() }
}