简体   繁体   English

AngularJS控制器,服务命名最佳实践

[英]AngularJS controller, service naming best practice

I am planning to build an Angular app that can be really scale. 我打算构建一个可以真正扩展的Angular应用程序。 Meaning, it will contains many part that will be develop by different people and will be adding in new part / feature from time to time. 意思是,它将包含许多将由不同的人开发的部分,并将不时添加新的部分/功能。

I have read some articles about Angular best practices in naming and folder structure organization, such as: 我已经阅读了一些关于命名和文件夹结构组织中的Angular最佳实践的文章,例如:

Angularjs code/naming conventions Angularjs代码/命名约定

AngularJS best practices for module declaration? AngularJS模块声明的最佳实践?

Angular - Best practice to structure modules Angular - 构建模块的最佳实践

All of it focuses on folder structure & module naming. 所有这些都侧重于文件夹结构和模块命名。 But how about the controller & services naming conventions? 但控制器和服务命名约定如何?

For example, if I have a structure like this: 例如,如果我有这样的结构:

angular.module("myApp",['myApp.groups','myApp.users']);

angular.module("myApp.groups",['myApp.groups.controllers','myApp.groups.directives']);

angular.module("myApp.users",['myApp.users.controllers','myApp.users.directives']);

Should I name controller for myApp.groups.controllers module to be myApp.GroupsController ? 我应该将myApp.groups.controllers模块的控制器命名为myApp.GroupsController吗? Or just GroupsController ? 或者只是GroupsController If just GroupsController , it will be possible conflict of naming if someone else develop another component with controller named GroupsController . 如果只是GroupsController ,如果其他人用名为GroupsController控制器开发另一个组件,则可能会发生命名冲突。

So, what is the best practice for naming controllers & services for huge application that will scale? 那么,为可扩展的大型应用程序命名控制器和服务的最佳实践是什么?

This post by JohnPaPa has a few good explanations. JohnPaPa的这篇文章有一些很好的解释。 Although some may disagree, but it provides insights and reasons for better understanding. 虽然有些人可能不同意,但它提供了更好理解的见解和理由。

爸爸的图

If you want something that will scale, have a look at cg-angular it provides a really good directory structure and has some good generators for everything you would need. 如果你想要扩展的东西,看看cg-angular它提供了一个非常好的目录结构,并为你需要的一切提供了一些好的生成器。 As for style guide Google is a great start 至于风格指南, Google是一个很好的开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM