4

Could anyone explain me what is the pourpuse of create new modules in angularjs application, I have already read the documentation, but we are not quite sure about when is appropiate to create a new module or use our own application module when you create a new service, directive, etc..

4

2 回答 2

1

I would like to add some thoughts after reading a bit more about the subject:

JAndy, you are right in the general concept, but to be more specific in when do you have to use angularjs modules I think I got a clear answer in this post

Basically we have 3 ways of structuring our angularjs projects:

  1. angular-seed
  2. Yeoman
  3. Structure the project in Modules

Depending of how big is your project you can take one aproach or another.

Basically writing new modules in angularjs helps you to pack functionalities that are related, one of the advantages of this approach is if a new developer comes into your team he can get a general overview and find things easier than if you only have one module, another one is to reuse functionality accross other projects.

于 2013-04-26T10:43:44.783 回答
0

I'd like to answer this question in a more general style than being specific.

Why was the ISS not build as one gigantic station instead of multiple independent modules ? The reason behind modules is to separate responsibilities, decouple a construction, etc. In terms of programming it means to have logic, spread over multiple small modules. That way, you not only know exactly where to look if anything goes wrong or you need to extend some functionality, it'll also guarantee that your whole ISS( your application ) will not entirely fail if one of your modules fails. This of course, also requires certain aspects of programming styles, most important in this context, to hold module interaction and communication loosely coupled (which I just assume).

So whenever you want to implement new stuff, which does not fit in any other existent code or module, you should create a new, independent module, which is specialized to fulfill a certain task.

Even if I'm not using AngularJS on regular bases, I'm sure the same idea of modularization will fit in there.

于 2013-04-19T14:33:33.623 回答