0

I am attempting to create a number of AngularJS libraries that can be re-used across apps and modules. I thought i was doing everything correctly but am still having a problem.

First I create a file that defines a generic module (app.ui) and attaches a provider (LayoutManager) to it ... (I am using a jQuery plugin called "jQuery Layout". This provider allows the app to access and manipulate the layout parameters. I don't want to get hung up on the details of the plugin however. The question is more general, but thought I should at least provide some explanation)

angular.module("app.ui", [])
    .provider('LayoutManager', [function () {
        'use strict';

        var appLayout = $('body').layout(),
        moduleNavLayout = $('.module-nav-container').layout(),
        moduleLayout = $('.module-content-container').layout();

        return {
            $get: function () {
                return {
                    ApplicationLayout: appLayout,
                    ModuleNavigatonLayout: moduleNavLayout,
                    ModuleContentLayout: moduleLayout
                }
            }
        }
    }]);

Then I identify the module (app.ui) as a dependency of the "app" (ListMgrApp) I want to use it in.

angular.module("ListMgrApp", ["ui.router", "app.services", "app.ui"])

Then I inject (is that the correct terminology?) the specific provider (LayoutManager) into the application ...

angular.module("ListMgrApp", ["ui.router", "app.services", "app.ui"]).
    config(['$stateProvider', 'LayoutManager',
        function ($stateProvider, layout) {
            'use strict';
            // initialization code goes here
        }]);

While it appears that the code inside the LayoutManager provider DOES execute, which I believe is due to it being included as a dependency for the app, I am still getting the following error from the application when it runs.

Uncaught Error: [$injector:modulerr] Failed to instantiate module ListMgrApp due to:
Error: [$injector:unpr] Unknown provider: LayoutManager

I have verified that the source code for all required files are being successfully down loaded.

What am I missing?

RESOLUTION

Thanks elclanrs for the answer! I just wanted to add what exactly I updated to make it work.

I added "Provider" to the name of the provider (LayoutManager) in the config() method of the app (ListMgrApp). I had originally thought I was supposed to also change the name of "LayoutManager" in the provider code but misread the original solution comment. Only change the name in the app config() method. I thought I would point it out here just in case someone else was a "skimmer" and missed it.

angular.module("ListMgrApp", ["ui.router", "app.services", "app.ui"]).
    config(['$stateProvider', 'LayoutManagerProvider',
        function ($stateProvider, layout) {
            'use strict';
            // initialization code goes here
        }]);
Capitaine
  • 1,923
  • 6
  • 27
  • 46
Gary O. Stenstrom
  • 2,284
  • 9
  • 38
  • 59
  • 1
    Try `config(['$stateProvider', 'LayoutManagerProvider'` – elclanrs Feb 19 '14 at 23:39
  • I deleted my last comment because it had said that this did NOT work ...I Was wrong (I left in some test code that it was choking on). This worked perfectly. If you could post it as an "answer" I will mark it as correct. I will also post the answer to my OP. – Gary O. Stenstrom Feb 19 '14 at 23:46
  • Your question looks like a dup of http://stackoverflow.com/questions/15286588/how-to-inject-dependency-into-module-configconfigfn-in-angular, http://stackoverflow.com/questions/19966013/angularjs-inject-provider-to-module-config and http://stackoverflow.com/questions/12903338/angularjs-dependency-injection-of-value-inside-of-module-config – elclanrs Feb 19 '14 at 23:46
  • I must have done a crappy search ... I saw a lot of posts but none of these three. Sorry. – Gary O. Stenstrom Feb 19 '14 at 23:54
  • We all do it. It's hard to find about it if you didn't know what to search for, plus Angular's documentation isn't the greatest... Glad you solved the issue. – elclanrs Feb 19 '14 at 23:57

0 Answers0