Angular JS 命名约定($、camelCase 和 PascalCase) [英] Angular JS naming conventions ($, camelCase and PascalCase)

查看:32
本文介绍了Angular JS 命名约定($、camelCase 和 PascalCase)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS 中使用 $ 作为提供者前缀的约定是什么?我应该在自己的代码中为所有自定义服务添加前缀吗?

What is the convention in AngularJS for prefixing providers with $? Should I prefix all custom services in my own code?

看起来所有带有 angular 的东西都有前缀服务,例如$http.然而,在大多数文章中,控制器没有以 $ 为前缀.此外,所有 Angular 代码都带有以 camelCase 命名的服务,但是我也在许多在线博客中看到了 PascalCase.哪个是约定俗成的?

Looks like all things that come with angular have prefixed services, e.g. $http. Controllers, however, are not prefixed with $ in most articles. Also, all angular code comes with services named in camelCase, however I've also seen PascalCase in many blogs online. Which one is the convention?

推荐答案

文档声明了内部服务的这个约定,但也声明您不应该为自己的服务这样做以减少命名冲突.

The docs state this convention for internal services, but also state you should not do it for your own services to reduce naming collisions.

http://docs.angularjs.org/guide/concepts#angular_namespace

另外,关于camelCase,文档说使用camelCase.

Also, regarding camelCase, the docs say to use camelCase.

Angular 使用带破折号的名称作为属性名称,使用驼峰命名法作为对应的指令名称

Angular uses name-with-dashes for attribute names and camelCase for the corresponding directive name

http://docs.angularjs.org/tutorial/step_00

这篇关于Angular JS 命名约定($、camelCase 和 PascalCase)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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