AngularJS 应用程序文件结构 [英] AngularJS application file structure

查看:37
本文介绍了AngularJS 应用程序文件结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个大型 AngularJS 应用程序中,我的所有控制器都在一个controllers.js"文件中,这对我来说似乎有点难以维护.有没有更好的方法来做到这一点,例如:

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...

推荐答案

有很多方法可以组织您的代码.您可以查看以下链接

There are lot's of ways to organize your code. You can look in the following links

您可以遵循他们的标准,也可以制定自己的标准.

You can follow their standard or you can make your own.

尝试遵循以下准则:

  • 控制器不应太长,如果太长则说明它在处理多个职责
  • 尝试在您的系统中使用指令和服务来重用您的代码/逻辑
  • 指令是 Angualrjs 中最强大的东西,尽量发挥它的最大优势.
  • 编写测试;更好的是,您可以尝试使用 AngularJS 练习 TDD

这篇关于AngularJS 应用程序文件结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆