我有嵌套的 angularJS 选项卡,我的问题是我希望能够打印选择内容列表,无论用户从父选项卡和子选项卡中选择什么。当用户单击打印列表时它会打印所有页面吗? http://plnkr.co/edit/8iYDDRaGHi2iNm0MWGfL?p=preview
$scope.printEmployeeList = function (divName) {
var printContents = document.getElementById(divName).innerHTML;
var popupWin = window.open('', '_blank', 'width=800,height=700');
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();
}
最佳答案
您可以在按钮单击时编写一条指令,它将为您提供所选选项卡的内容。
标记
<button print-content="content">Employee List</button>
指令
app.directive('printContent', function($document) {
return {
restrict: 'A',
compile: function(element, attrs) {
element.on('click', function(event) {
console.log($document.find('#'+ attrs.printContent).find('.tab-pane.active').html());
//you code add your print code here
});
}
}
});
关于javascript - angularJS UI选项卡打印选项卡中选定的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567205/