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?

4
  • 1
    You didn't define jszip service, You defined jszip module. Commented Sep 6, 2016 at 18:43
  • I created a jszip module because I thought that was the method to be taken to use jszip in a service Commented Sep 6, 2016 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 _. Commented Sep 6, 2016 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 Commented Sep 6, 2016 at 18:52

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.