我已经尝试在网页上复制/粘贴示例代码: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
我真的很感激一些帮助,因为我已经坚持了很长时间,而且似乎无法更接近解决方案。