0

I'm trying to use underscore or lodash in angular.module("",[]).config(function(){/* Here */}), but it is expecting a Provider and throwing Unknown provider.

  • Should I just use _ from global scope? (which is not preferrable)
  • Is there a way to inject utility like underscore/lodash in module config?
skmasq
  • 4,470
  • 6
  • 42
  • 77
  • I deleted my answer as there didn't appear to be a provider which could be injected in to the `.config()` call. Only a service was available for use in controllers. The module appears to be quite old anyway. – Adam Nierzad Mar 16 '17 at 15:58
  • Use `app.constant("_", window._);` Constants are injectable during both the config phase and the run phase. See [AngularJS Developer Guide - Loading Modules and Dependencies](https://docs.angularjs.org/guide/module#module-loading-dependencies) and [AngularJS Service Components Reference - Constant](https://docs.angularjs.org/api/auto/service/$provide#constant). – georgeawg Mar 17 '17 at 03:02

1 Answers1

-1

After further investigation the module I linked wasn't suitable for your requirement. However, I did manage to dig up an older SO question which has some information about defining lodash in an Angular constant, this can be injected in to the .config() call.

Here is the question: How to make lodash work with Angular JS?

I hope this is more useful.

Community
  • 1
  • 1
Adam Nierzad
  • 942
  • 6
  • 19