错误:[$注入器:strictdi]函数($window)-需要显式注释



如何在我的代码angularjs中运行工厂

如何在我的代码中使用工厂服务请帮助我这是数据导出excel。如果你有任何其他的逻辑或例子表转换为excel,请与我分享我需要这个。但此时我需要show来运行此代码我想运行.factory('Excel',函数($window(这个工厂*

错误:[$injector:strictdi]函数($window(未使用显式注释,无法在严格模式中调用

//模块

export default angular.module('goApp.main', [ngRoute])
.config(routing).factory('Excel',function($window){
var uri='data:application/vnd.ms-excel;base64,',
template='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
base64=function(s){return $window.btoa(unescape(encodeURIComponent(s)));},
format=function(s,c){return s.replace(/{(w+)}/g,function(m,p){return c[p];})};
return {
tableToExcel:function(tableId,worksheetName){
var table=$(tableId),
ctx={worksheet:worksheetName,table:table.html()},
href=uri+base64(format(template,ctx));
return href;
}
};
})
.component('main', {
template: require('./main.html'),
controller: MainController,
controllerAs: 'Ctrlmain'
})
.name;

//控制器

import angular from 'angular';
const ngRoute = require('angular-route');
import routing from './main.routes';
export class MainController {
/*@ngInject*/
constructor($http, Excel,$timeout,$window,$scope,socket, $location, Auth,NgMap,$uibModal) {
this.$http = $http;
this.socket = socket;
$scope.exportToExcel=function(tableId){ // ex: '#my-table'
var exportHref=Excel.tableToExcel(tableId,'sheet name');
$timeout(function(){location.href=exportHref;},100); // trigger download
}
}
}

为工厂使用内联数组注释:

̶e̶x̶p̶o̶r̶t̶ ̶d̶e̶f̶a̶u̶l̶t̶ ̶a̶n̶g̶u̶l̶a̶r̶.̶m̶o̶d̶u̶l̶e̶(̶'̶g̶o̶A̶p̶p̶.̶m̶a̶i̶n̶'̶,̶ ̶[̶n̶g̶R̶o̶u̶t̶e̶]̶)̶
export default angular.module('goApp.main', ['ngRoute'])
̶.̶c̶o̶n̶f̶i̶g̶(̶r̶o̶u̶t̶i̶n̶g̶)̶.̶f̶a̶c̶t̶o̶r̶y̶(̶'̶E̶x̶c̶e̶l̶'̶,̶f̶u̶n̶c̶t̶i̶o̶n̶(̶$̶w̶i̶n̶d̶o̶w̶)̶{̶
.config(routing).factory('Excel',['$window', function($window){
var uri='data:application/vnd.ms-excel;base64,',
template='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
base64=function(s){return $window.btoa(unescape(encodeURIComponent(s)));},
format=function(s,c){return s.replace(/{(w+)}/g,function(m,p){return c[p];})};
return {
tableToExcel:function(tableId,worksheetName){
var table=$(tableId),
ctx={worksheet:worksheetName,table:table.html()},
href=uri+base64(format(template,ctx));
return href;
}
};
̶}̶)̶
}])

有关更多信息,请参阅

  • AngularJS开发人员指南-内联数组注释
  • AngularJS错误参考-错误:$injector:sstrictdi-需要显式注释

最新更新