0

My code is like this

App.js
angular.module('mailerApp', [
    'mailerApp.services',
    'mailerApp.controllers',
    'ui.bootstrap',
    'angular-loading-bar',
    'textAngular',
    'angularFileUpload'
]);

Cotrollers.js
angular.module('mailerApp.controllers').controller('MailerCntrl', ['$scope', 'FileUploader', function ($scope, FileUploader) {

}]);

Services.JS
angular.module('mailerApp.services', []).factory('rateRequestService', ['$http', rateRequestService]);
function rateRequestService($http) {
    var service = { getData: getData };
    return service;
    function getData() {
        return $http({
            method: 'Get',
            url: '../services/RateRequestWS.asmx/GetReadOnlyData?'
        });
    }
}

HTML
body ng-app="mailerApp" ng-controller="MailerCntrl">
</body>

Everything looks okay to me, But this throws an error

 Uncaught Error: [$injector:nomod] Module 'mailerApp.controllers' is not available! You either misspelled the module name or forgot to
 load it. If registering a module ensure that you specify the
 dependencies as the second argument.

Can any one point out What I am doing wrong here?

1
  • 1
    If you are creating the module you need to add an empty array as the second argument: angular.module('mailerApp.controllers', []) (Just like you have with mailarApp.services) Commented Dec 24, 2014 at 12:06

2 Answers 2

4

Instead of

angular.module('mailerApp.controllers').controller...

You need to do

angular.module('mailerApp').controller... // to add the controller to the mailerApp module
angular.module('mailerApp.controllers', []).controller... // to add the controller to a new mailerApp.controllers module

And the same goes with;

angular.module('mailerApp.services').factory... 

Instead you need to

angular.module('mailerApp').factory... // add the factory to the mailerApp module
angular.module('mailerApp.services', []).factory... // add the factory to a new mailerApp.services module

When you create and angular module, you give it a name and the list of dependencies in the array;

var module = angular.module('<module_name>', [<dependencies>])

But then when you add a controller/factory to the module, you'll need to either use the module object you created.

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

4 Comments

This is incorrect as he wants mailerApp.controllers and mailerApp.services as separate modules (as he has added them as dependent modules to his main module).
@tasseKATT I've added that in the edit to the answer.
Please also update your answer to remove the first part (which is not correct)
I've added a more detailed explanation. Thanks @Anzeo
3
  1. when you write angular.module('mailerApp.controllers', [ ]), you create new module as 'mailerApp.controllers' and in second parameter you pass dependencies.

  2. and when you write angular.module('mailerApp.controllers') it references previously created module.

But in your case your directly referencing module without creating it, therefore it gives you error for that. Same goes for other cases

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.