1

I am newbie to angularjs and i have to know the code structure and directory structure in angularjs

My directory Structure

My Doubts are

1)I want to know is the above directory structure is correct

2)Is it advisable to use controller for every individual module separately

3)Is correct way to write all run ,config and declaring module plugin in the same file (ex:app.js)

2
  • 2
    In my understanding, directory structure is for you. It helps you maintain code. Also every module should have separate controllers, and for any dependent modules, you can have services. Third, app.js is for configuration of app and all initialization of plugins should be done here. In an Idea scenario, app.js known wxgernal resources and initialize them. Controller should not be aware about the logic of initializing them. Commented Apr 12, 2016 at 4:38
  • Thanks @Rajesh for clearing doubts,could you share any sample where the project is with controllers,directives,services and factory,it would help me refine,because i've a huge doubt in working of services and factory Commented Apr 12, 2016 at 4:43

2 Answers 2

1

There is most widely accepted style guide for angularjs projects even angular team support this style guide by john papa. He is the active member in the angular core community. He has created style guide for angular1 and angular2.

even you can use yeoman tool to get scaffolding done for you and they follow these style guide angular project generator.

follow the instruction, after that it will be like

yo angular [app-name]

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

2 Comments

glad you liked the style guide :)
I am so glad to see your comment @JohnPapa :). yeah, your style guide is our official style guide .
0

I want to know is the above directory structure is correct.

Its totally depends on you how would you organize you project setup, there is nothing hard and fast rule that you have to follow to setup your project structure. well if we talk about your structure it seems to be good setup you have established except images folder i would prefer image folder in the asset folder. otherwise your setup seems to be fine.

is it advisable to use controller for every individual module separately

Yes, its good practice to use a separate controller for every module, and categorize them as per you folder structure.

although there are a lot of projects are there from where you can easily got your all answers, also there are many popular repository's are there which describe the best folder structure for the project setup you can also refer to most popular style guide of angular here -

2 Comments

on which way i should go ahead @pardeep jain
Which you found more reliable and efficient according to your use case, i recomend john papa style guide @madhavan

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.