【问题标题】:How to call print function in new window after page is loaded?页面加载后如何在新窗口中调用打印功能?
【发布时间】:2015-07-09 16:10:45
【问题描述】:

好的,我有这个按钮:

我有这个确认票的功能:

   $scope.ConfirmTicketPayOut = function (ticketPin, username)
    {
        $scope.ticketPin = ticketPin;
        localStorage.setItem("ticketPin", ticketPin);
        accountDataProviderService.confirmTicketPayOut(ticketPin, username)
        .then(function (response) {

            $scope.confirmTicketPayOut = response;
            if ($scope.confirmTicketPayOut.Result == true)
            {
                    var w = $window.open('/account/ticketprint');
                    angular.element(w).bind('load', function () {
                        w.print();
                    });
            }   
        });
    }

我有问题,因为当用户单击按钮时,我需要打开带有数据的新窗口并调用打印选项。在这种情况下,我得到打印选项并且新窗口打开但页面是空白的,所以我的结论是在出现打印选项后加载页面。我需要同时加载页面和显示打印选项,但没有$timeout。这可能吗?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    尝试使用角度事件viewContentLoaded。在触发此事件后调用您的方法。

    例子

    $scope.$on('$viewContentLoaded', function() {
    
        // Your method call
    
    }
    

    【讨论】:

    • 在您的打印控制器中。您在哪里调用打印功能
    • 这样吗? $scope.$on('$viewContentLoaded', function () { var w = $window.open('/account/ticketprint'); angular.element(w).bind('load', function () { w.打印();});});
    猜你喜欢
    • 1970-01-01
    • 2016-01-27
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    相关资源
    最近更新 更多