AngularJS应用文件结构 [英] AngularJS application file structure
本文介绍了AngularJS应用文件结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在有我在一个controllers.js文件中的所有控制器的大型AngularJS应用程序似乎有点非维护我。有没有更好的办法做到这一点,如:
On a large AngularJS application having all my controllers in a single "controllers.js" file seems a little un-maintainable to me. Is there a better way to do this such as:
\js\controllers\myController.js
\js\controllers\yourController.js
\js\controllers\ourController.js
和也适用于过滤器,服务指令等...
and that also applies for filters, services, directives etc...
推荐答案
有很多方法来组织你的code很多的。你可以看一下在以下链接
There are lot's of ways to organize your code. You can look in the following links
- Building Huuuuuge Apps with AngularJS
- Code Organization in Large AngularJS and JavaScript Applications
- Code organization in all type project in angularjs
您可以按照自己的标准,也可以自己动手做。
You can follow their standard or you can make your own.
试着遵循以下指导原则:
Try to follow the following guidelines:
- Contollers应该不会太长,如果太长则是处理多重责任
- 尝试使用指令和服务在系统中重用你的code /逻辑
- 指令是Angualrjs最强大的东西,想方设法把它最大的优势。
- 写测试;甚至更好,你可以尝试用AngularJS实践TDD
这篇关于AngularJS应用文件结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文