【问题标题】:Angular formly only shows blank page when printing formAngular 仅在打印表单时显示空白页
【发布时间】:2016-11-07 18:01:26
【问题描述】:

我正在尝试创建一个按钮,用户可以在其中打印页面以供记录,但使用 formly 时它一直显示为空白,我假设是因为表单是动态生成的。我在“打印”按钮中使用了打印指令:

    (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>

当我按下按钮时会弹出打印窗口,但是除了显示页面名称和日期之外,页面是空白的。我怎样才能得到正式的字段来打印出来?

【问题讨论】:

    标签: javascript angularjs forms printing angular-formly


    【解决方案1】:

    看看angularPrint。它让一切变得超级简单。

    【讨论】:

      猜你喜欢
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多