angularjs – 角度 – 结构模块的最佳实践

前端之家收集整理的这篇文章主要介绍了angularjs – 角度 – 结构模块的最佳实践前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是新来的,所以请忍受我.我正在阅读另一天的文章/文档,突出显示了在应用程序中构建模块的最佳方法,只能轻松记住它.
  1. App.controllers
  2. App.services
  3. ....
  4.  
  5. angular.module('App',[App.controllers,App.services ...);

这个代码示例很可能是不正确的,但重点是将控制器,服务等组合在一个命名空间中.

有人可以扩大这种做法吗?

企业项目组织

我组织我的角度项目的方式是:

  1. /app
  2. /img # application-level images
  3. /css # application-level css styles
  4. /js # application-level javascripts
  5. /modules # application modules
  6. /gallery # independent module with its own infrastructure
  7. /controllers # gallery module's controllers
  8. /css # gallery module's css styles
  9. /directives # gallery module's directives
  10. /img # gallery module's images
  11. /filters # gallery module's filters
  12. /services # gallery module's services
  13. /views # gallery module's views (htmls)
  14. / ... # other gallery module component folders
  15. galleryMod.js # the module itself
  16.  
  17. /user # independent module with its own infrastructure
  18. /controllers # user module's controllers
  19. / ... # other user module component folders
  20. userMod.js # the module itself
  21.  
  22. / ... # other modules
  23.  
  24. / ... # other application-level folders
  25. index.html

替代企业项目组织(简化)

  1. /app
  2. /img # application-level images
  3. /css # application-level css styles
  4. /js # application-level javascripts
  5. /modules # application modules
  6. /gallery # independent module with its own infrastructure
  7. /js # gallery module's javascripts (includes
  8. # services.js,directives.js,filters.js,...)
  9. /css # gallery module's css styles
  10. /img # gallery module's images
  11. /views # gallery module's views (htmls,"partials")
  12. / ... # other gallery module component folders
  13. galleryMod.js # the module itself
  14.  
  15. /user # independent module with its own infrastructure
  16. /controllers # user module's controllers
  17. / ... # other user module component folders
  18. userMod.js # the module itself
  19.  
  20. / ... # other modules
  21.  
  22. / ... # other application-level folders
  23. index.html

中间项目组织(无模块)

  1. /app
  2. /img # application's images
  3. /css # application's css styles
  4. /controllers # application's controllers
  5. /directives # application's directives
  6. /filters # application's filters
  7. /services # application's services
  8. /views # application's views (htmls)
  9. / ... # other component folders
  10. index.html

简单的项目组织(就像种子)

  1. /app
  2. /img # application's images
  3. /css # application's css styles
  4. /js # application's javascripts (includes
  5. # services.js,...)
  6. /views # application's views (htmls),e.g. partials
  7. / ... # other component folders
  8. index.html

使用您的项目需要组织的方式,不要选择不必要的项目复杂化的方式.

猜你在找的Angularjs相关文章