Rocco Musolino Rocco Musolino - 1 month ago 8
AngularJS Question

Error: [$injector:unpr] Unknown provider: ngCsvProvider <- ngCsv <- dynamicDemoController

Here is my scenario:


  • file A.js that define the main module.

  • file B.js lazy-loaded (after angular bootstrap) that contains a controller and some directives.



file A.js:

var APP = angular.module('app.hello', ['ui.router', 'ngAnimate', 'ngTable', 'ngSanitize', 'ngCsv']);

(function() {

APP.config(function ($controllerProvider, $compileProvider) {
APP.loadController = $controllerProvider.register;
APP.loadDirective = $compileProvider.directive;
});

})();


file B.js:

(function() {
"use strict";

APP.loadController("dynamicDemoController", dynamicDemoController);
dynamicDemoController.$inject = ["NgTableParams", "ngCsv"]; // <-- err

function dynamicDemoController(NgTableParams, CSV) {
// ...
}

})();


I'm injecting
NgTableParams
flawlessly but I'm not being able to "inject" the
ngCsv
module and I'm getting this error in console:


Error: [$injector:unpr] Unknown provider: ngCsvProvider <- ngCsv <-
dynamicDemoController


Any idea what am I possibly missing?

Answer

You are trying to inject a module in your controller, that's why its causing error.

  dynamicDemoController.$inject = ["NgTableParams", "ngCsv"]; // <-- err

ngCsv is a module and not a service.

Loading of module's should be limited to angular.module.

var myapp = angular.module('myapp', ['ngCsv'])
Comments