如何使用angular-screenshot打印整个DOM元素?

时间:2018-07-09 18:09:53

标签: javascript html angularjs screenshot angularjs-3rd-party

我已经尝试在网页上复制/粘贴示例代码:https://weihanchen.github.io/angular-screenshot/ 问题是他们为此使用了整个控制器,而我的控制器却被视图分开了。这就是我将它们添加到我的“主要” js中的方式:

    .state("main.pallet", {
        url: "/palletize",
        templateUrl: "app/views/pallet.html",
        data: {pageTitle: 'Entarimado.'},
        controller: "Pallet",
        resolve: {
            deps: ['$ocLazyLoad', function($ocLazyLoad) {
                return $ocLazyLoad.load({
                    name: 'TepaPrime',
                    insertBefore: '#ng_load_plugins_before', // load the above css files before '#ng_load_plugins_before'
                    files: [
                        'app/js/filters/filters.js',
                        'app/js/directives/numericFormat.js',
                        'app/js/directives/trimText.js',
                        'app/js/directives/nextOnEnter.js',
                        'app/js/factories/crud.factory.js',
                        'app/js/controllers/modals/palletContent.js',
                        'app/js/controllers/pallet.js',
                        'app/js/services/printDocument.js'
                    ]                    
                });
            }]
        }
    })

这是我的printDocument.js,我在其中粘贴了示例中的代码(并对其进行了修改以使其正常工作):

'use strict';
function appController($scope) {
  var self = this;
  self.fullScreenApi;
  self.downloadFull = downloadFull;
  this.downloadFull = function() {
      if (self.fullScreenApi) self.fullScreenApi.downloadFull();
   }
   return downloadFull;
}
angular
    .module('TepaPrime')
    .service('printDocument', appController);

然后通过执行以下操作将其注入到视图的控制器中:

function Pallet($rootScope, $scope, $state, $timeout, $uibModal, $http, $filter, crud, sessionService, printDocument) {
  ...
}

问题是它不起作用,它使整个页面崩溃并引发此错误:

  

错误:[$ injector:unpr] http://errors.angularjs.org/1.5.0/ $ injector / unpr?p0 = copeProvider%20%3C-%20%24scope%20%3C-%20printDocument

我真的很乐意提供帮助,因为我已经坚持了很长时间,而且似乎无法找到解决方案。

1 个答案:

答案 0 :(得分:0)

经过漫长的奋斗,我能够通过将

的html更改来修复它
      <button class="btn btn-info" ng-if="appCtrl.isFullOpen" ng-click="appCtrl.downloadFull()">
        <i class="material-icons">Descargar tabla</i>
      </button>

收件人:

      <button class="btn btn-info" ng-if="appCtrl.isFullOpen" ng-click="appCtrl.fullScreenApi.downloadFull()">
        <i class="material-icons">Descargar tabla</i>
      </button>

问题在于downloadFull()函数位于fullscreenApi内部。