Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I get this error when I try to run my application.

Argument 'CampaignsSettingsController' is not a function, got undefined

My controller is defined here:

// Called Second
var campaignsSettingsModule;
campaignsSettingsModule = angular.module('campaignsSettings');
campaignsSettingsModule.controller(
    'CampaignsSettingsController', [
        '$scope',
        '$window',
        'CampaignAdvancedSettings',
        function($scope, $window, CampaignAdvancedSettings) {
            // my controller code here
        }
    ]
);

And the campaignSettings module is called like this:

// Called first
var modules = ['evApp', 'campaignsSettings'];

for (var i = 0, length = modules.length; i < length; i++) {
    angular.module(modules[i], []).config(function($interpolateProvider){
        $interpolateProvider.startSymbol('{[').endSymbol(']}');
    });
}

The order in which these files are called (dunno if it makes a difference) is indicated above the code.

What would be the reason for getting the undefined error? Where can I start looking into solving this problem. I've read through various answers here, but I still can't get it fixed.

share|improve this question
    
Check with this checklist:stackoverflow.com/a/26797874/930170 – Sergey Panfilov Jul 29 at 8:04
    
As far as I am always doing custom modules are always injected on the second of param of angular.module('thisModuleName', ['inject', 'your', 'modules', 'here']) also, dont wrap it in for loop. It looks weird. – The Green Foxx Jul 29 at 8:09
    
By the way I wrote a personal template/boiler plate for angularjs this might help you construct your angular project easier. Here. github.com/jofftiquez/angular-app-starter-pack – The Green Foxx Jul 29 at 8:13
    
Seems like a dumb question, but have you remembered to include the JS file on your index file? – McBoman Jul 29 at 8:19

Change

From:

campaignsSettingsModule = angular.module('campaignsSettings');

To:

campaignsSettingsModule = angular.module('campaignsSettings',[]);
share|improve this answer

I think angular.module(modules[i], []) section in for loop defines new Angular module. So, your previous declaration of module ignored.

Change it like that; (without second parameter)

angular.module(modules[i])
share|improve this answer
    
you can not define multiple modules.you can inject multiple dependencies like angular.module('some name',['dependency1','dependency2']) – naresh vadlakonda Jul 29 at 8:27
    
Can you explain why this code doesn't work? It has no dependencies included or excluded. If you want to get "reference" to your module you should only set first parameter like angular.module('myApp'). That's what I'm saying. Your downvote is illogical. – Tuğca Eker Jul 29 at 8:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.