1

I'm trying to use jszip in an angular service but it is not written using angular. I've looked at the answers to this question Inject non-angular JS libraries and this question How to make lodash work with Angular JS? which are both trying to get lodash to work in angular. I've tried creating a module like this

angular.module('jszip', [])
    .constant('_', window._)
    .run(function($rootScope) {
        $rootScope._ = window._;
    });

And injecting it into a service like this

app.factory('FileService', ['Restangular', 'DeviceService', 'jszip',
    function FileUploadService(Restangular, DeviceService, jszip) {
    // ....
}]);

but I get this error

angular.js:10147 Error: [$injector:unpr] Unknown provider: jszipProvider <- jszip <- FileService

Also I'm assuming the underscore is something specific for lodash? In general how do I add a non angular dependency?

Community
  • 1
  • 1
gary69
  • 3,620
  • 6
  • 36
  • 50
  • 1
    You didn't define jszip service, You defined jszip module. – Estus Flask Sep 06 '16 at 18:43
  • I created a jszip module because I thought that was the method to be taken to use jszip in a service – gary69 Sep 06 '16 at 18:45
  • 1
    It looks like you're confusing modules with services. You can't inject a module. You can load it and then inject its service. Module's name is `jszip`. And service's name is `_`. – Estus Flask Sep 06 '16 at 18:50
  • thank you, I get the same unknown provider exception when I inject '_' because my browser is not loading the folder that holds this file – gary69 Sep 06 '16 at 18:52

2 Answers2

3

The problem it's not the $rootScope._ = window._;. Probably the module file is not getting loaded, and when you try to inject into FileService, he dosen't reconize.

Try to aceess the file in the browser inspector

Fabio Picheli
  • 939
  • 11
  • 27
0

My module wasn't loading because I wasn't including the file containing the code in any of my html files like this

<script src="app/main/export-import/export-import.service.js"></script>

This is also how you include non angular dependencies

<script src="export/libs/jszip/jszip.js"></script>
gary69
  • 3,620
  • 6
  • 36
  • 50