Javascript angularjs+;下载csv文件+;错误:[$injector:unpr]未知提供程序
我是新来安格拉斯的 我尝试下载csv文件。所以我尝试使用angular sanitize和ng csv文件 Index.htmlJavascript angularjs+;下载csv文件+;错误:[$injector:unpr]未知提供程序,javascript,angularjs,csv,Javascript,Angularjs,Csv,我是新来安格拉斯的 我尝试下载csv文件。所以我尝试使用angular sanitize和ng csv文件 Index.html <!DOCTYPE html> <html lang="en"> <head> <script src="vendor/theme_files/js/jquery.min.js"></script> </head> <body ng-app="myA
<!DOCTYPE html>
<html lang="en">
<head>
<script src="vendor/theme_files/js/jquery.min.js"></script>
</head>
<body ng-app="myApp" class="nav-md">
<div class="container body" ui-view></div>
<script src="vendor/angular/angular.js"></script>
<script src="vendor/angular-resource/angular-resource.js"></script>
<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
<script src="js/services/lb-services.js"></script>
<script src="vendor/angular-sanitize/angular-sanitize.js"></script>
<script src="vendor/ng-csv/ng-csv.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/offerLetterCtl.js"></script>
<script src="js/services/offerLetter.js"></script>
</body>
</html>
offerLetterCtl.js(控制器文件夹)
js(服务文件夹)
创建\u offer\u letter.html
<button type="button" ng-csv="getArray()" csv-header="['Field A', 'Field B', 'Field C']" filename="test.csv">
Export
</button>
错误详细信息:
Error: [$injector:unpr] Unknown provider: ngSanitizeProvider <- ngSanitize <- offerLetterController
http://errors.angularjs.org/1.3.20/$injector/unpr?p0=ngSanitizeProvider%20%3C-%20ngSanitize%20%3C-"<div class="container body ng-scope" ui-view="">"fferLetterController
错误:[$injector:unpr]未知提供程序:ngSanitizeProvider我认为您没有在app.js中将ngSanatize模块添加到您的应用程序中。试着这样做:
angular.module('myApp', ['lbServices', 'ui.router', 'ngSanitize']).config(['$stateProvider', '$urlRouterProvider',
函数($stateProvider,$urlRouterProvider){
这至少是错误的:
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService',"ngSanitize", "ngCsv" ,function($scope, $location, offerLetterService) {
您的错误是,您在第一部分中有5个服务,而实际上只注入了3个。如果您将这些服务对齐,则会有所帮助:
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService',"ngSanitize", "ngCsv" ,function($scope, $location, offerLetterService, ngSanitize, ngCsv) {
除此之外,这也不正确:
angular.module('myApp').factory('offerLetterService', ['$q', '$timeout', '$http',
function($q, $timeout, $http,OfferLetter) {
您正在定义名为OfferleterService的工厂,我想您不想将其插入其中?已从控制器中删除注入。这应该可以工作
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService'
,function($scope, $location, offerLetterService) {
$scope.filename = "test";
}]);
你能帮个忙吗?请冷静下来。另外,编辑你的代码,让你的问题看起来更具可读性,一些代码现在已经格式化,一些行没有添加到app.js中的ngSanatize模块中,但是同样的错误。在你的浏览器控制台中也没有404没有找到某些.js文件?我确信,js文件正在加载
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService',"ngSanitize", "ngCsv" ,function($scope, $location, offerLetterService) {
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService',"ngSanitize", "ngCsv" ,function($scope, $location, offerLetterService, ngSanitize, ngCsv) {
angular.module('myApp').factory('offerLetterService', ['$q', '$timeout', '$http',
function($q, $timeout, $http,OfferLetter) {
angular.module('myApp').controller('offerLetterController', ['$scope', '$location', 'offerLetterService'
,function($scope, $location, offerLetterService) {
$scope.filename = "test";
}]);