0

I'm new in angularjs (I come from Java, Python, Objective-c) and I'm trying to achieve a modular design. But I don't see how app.js can "import"other modules and then how controllers import other controllers and keep them in separate files.

This is what I want:

/app

     /img -- application level images
     /css -- application level css
     /js

     app.js -- the main app module
     /modules
         /login
             /js
                 controllers.js --controllers for login module
                 directives.js --directives for login module

             /views -- views for login module
             /css
             /img
             loginModule.js -- Main login module definition

         /comment
             /js
                 controllers.js --controllers for login module
                 directives.js --directives for login module

             /views -- views for comment module
             /css
             /img
             commentModule.js -- Main comment module definition

     ...

     ...

     index.html
2

1 Answer 1

1

You can import other modules by making them a dependence.

In your case, it would probably be something like this.

angular.module("app.module", ["login.module", "comment.module"]);

You could also group 'core' functionalities into a module like core.module

angular.module("core.module", ["login.module", "comment.module"]);

Then make app.module depend on this module.

angular.module("app.module", ["core.module", "ui.router"]);

Hope that helps.

You reference your file in the index.html like so:

<html>
<head>
    <title></title>
</head>
<body>
    // HTML code here

    // angular libraries and other vendor libaries

    <script type="text/javascript" src="<path to each module>"></script>
    ...
    <script type="text/javascript" src="app.js"></script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Should I import each js module file on index.html ?
@Ricardo You'll need to provide the <script type="text/javascript" src="..path to script file"></script> in the correct order so your app module should be the last one because it depends on the other two in your index.html

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.