如何在用户单击按钮角度js时打开打印选项卡

时间:2015-04-16 17:36:51

标签: javascript jquery angularjs

当用户点击链接时,我有打印视图和控制器来打印结果:
<a data-ng-click="openPrintPreview(tab.countyID)">Employee List</a>

我想使用ng点击打开打印预览窗口并显示打印控制器,但我的问题是查看当前页面&#39; http://localhost/#/reception&#39;不是http://localhost/#/print/2

$scope.openPrintPreview = function(countyId){
     var popupWin = window.open('', '_blank', 'width=800,height=700');
         popupWin.print('#/print/' + countyId);
};

1 个答案:

答案 0 :(得分:0)

这是怎么做的

$scope.openPrintPreview = function(countyId) {
    var printUrl = window.location.origin + '/#/print/' + countyId;
    var popupWin = window.open(printUrl.toString(), '_blank', 'width=800,height=700');

    setTimeout(function () {
        popupWin.print();
    }, 1000);
};