Error: [$injector:strictdi] function($window) - Explicit annotation required
Error: [$injector:strictdi] function($window) - Explicit annotation required
如何在我的代码中 运行 工厂 angularjs
如何在我的代码中使用工厂服务请帮助我进行数据导出 excel。
如果您有将 table 转换为 excel 的任何其他逻辑或示例,请与我分享,我需要这个。但此时我需要向 运行 显示此代码
我想运行 .factory('Excel',function($window) 这个工厂*
Error: [$injector:strictdi] function($window) is not using explicit annotation and cannot be invoked in strict mode
//模块
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
如何在我的代码中使用工厂服务请帮助我进行数据导出 excel。 如果您有将 table 转换为 excel 的任何其他逻辑或示例,请与我分享,我需要这个。但此时我需要向 运行 显示此代码 我想运行 .factory('Excel',function($window) 这个工厂*
Error: [$injector:strictdi] function($window) is not using explicit annotation and cannot be invoked in strict mode
//模块
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;
}
};
̶}̶)̶
}])
有关详细信息,请参阅