繁体   English   中英

Angular在打印表格时仅显示空白页

[英]Angular formly only shows blank page when printing form

我正在尝试创建一个按钮,用户可以在该按钮上打印其记录页面,但由于使用了动态生成的表单,因此它会一直使用形式显示空白。 我在“打印”按钮中使用了打印指令:

    (function (angular) {
    'use strict';
    function printDirective() {
        var printSection = document.getElementById('printSection');
        // if there is no printing section, create one
        if (!printSection) {
            printSection = document.createElement('div');
            printSection.id = 'printSection';
            document.body.appendChild(printSection);
        }
        function link(scope, element, attrs) {
            element.on('click', function () {
                var elemToPrint = document.getElementById(attrs.printElementId);
                if (elemToPrint) {
                    printElement(elemToPrint);
                }
            });
            window.onafterprint = function () {
                // clean the print section before adding new content
                printSection.innerHTML = '';
            }
        }
        function printElement(elem) {
            // clones the element you want to print
            var domClone = elem.cloneNode(true);
            printSection.appendChild(domClone);
            window.print();
        }
        return {
            link: link,
            restrict: 'A'
        };
    }
    angular.module('formlyApp').directive('ngPrint', [printDirective]);
}(window.angular));

这是打印按钮:

<button class="btn btnSubmit" type="submit" ng-print  print-element-id="printSection" ng-hide="vm.iForm.$invalid">Print and Save</button>

当我按下按钮时,将弹出打印窗口,但是页面空白,而不显示页面名称和日期。 如何获得要打印的正式字段?

看一下angularPrint 它使超级容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM