2

I am new at angularjs. I am looking an application code.

<html> 
 .....
<script src="/my/app.main.js"></script>
<script src="/my/app.messages.js"></script>
<script src="/my/app.misc.js"></script>
<script src="/my/app.properties.js"></script>

and in these javascript filse icluding angularjs modules same name.

main.js file

(function () {
    'use strict';

    var app = angular.module('ngCookService');

    app.run([.....
        function (....) {            

        }]);
})();

messages.js file

(function () {
    "use strict";

    var app = angular.module('ngCookService');

    app.config(['$stateProvider', function ($stateProvider) { 
       ................
    }]);
})();

All of these js files include ngCookService module. And modules defined in self-invoking functions.

How this system works? Does earlier defined modules overriding? or new defined app module kills earlier objects?

1 Answer 1

6

When called with just the name of the module, angular.module() is a getter method and retrieves an existing module with that name. Therefore calling angular.module('ngCookService') does not override or replace the module.

For the getter to work, somewhere before it the setter must have been called. This is done by calling angular.module() with more than 1 argument (for example, a list of required modules)...

angular.module('ngCookService', ['ngRoute']);

If the setter is called more than once, then the module is being overridden.

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

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.