TheBronx TheBronx - 2 months ago 27x
AngularJS Question

registerModule with dependencies

I'm building an app with MEAN.JS and I'm trying to use a controller from another module. I've found that I can do this with dependency injection:

angular.module(‘MyModule’, [‘Dependency’]);

But the way modules are created in MEAN.JS is:


And I can't just pass a second parameter to
. So, how should I do this? Do I have to use both methods? Am I doing it wrong?


I want to add a new model:
are created by admins only, but can be seen by the "campaign owner" (another
). The create campaign form should list available Users, so the admin can select the one that's going to be the "owner" of that

The problem is, the create campaign form is controlled by
, how can I list
? I've used another controller (
) and thats the problem, it is undefined because we are in the


The problem was grunt autorestarting the app incorrectly:

I moved the controller from one module (folder) to another, but grunt was still trying to load it from the old path, and thus failing: Controller not found. I thought the problem was dependency injection, but you only have to close grunt (Ctrl+C) and run it again. Problem solved.

Anyways, thanks for the answer @gilBirman cause it is correct: there is no need to inject anything with MEANJS.


MEAN.js makes all the modules registered via registerModule available to all other modules in your app by adding it as a dependency to the main app called mean. Here's the part of the MEAN.js source code that does this:

var applicationModuleName = 'mean';
// Add a new vertical module
var registerModule = function(moduleName) {
    // Create angular module
    angular.module(moduleName, []);

    // Add the module to the AngularJS configuration file

So you're on the right track, however it sounds like you are trying to inject a controller. However, in angular, controllers are not injectable. You can inject services, factories, values, and constants.