Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS naming conventions ($, camelCase and PascalCase)

Tags:

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

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?

like image 478
glebm Avatar asked Apr 01 '13 17:04

glebm


People also ask

Should I use PascalCase or CamelCase?

Camel case and Pascal case are similar. Both demand variables made from compound words and have the first letter of each appended word written with an uppercase letter. The difference is that Pascal case requires the first letter to be uppercase as well, while camel case does not.

What is PascalCase naming style?

Pascal case -- or PascalCase -- is a programming naming convention where the first letter of each compound word in a variable is capitalized. The use of descriptive variable names is a software development best practice. However, modern programming languages do not allow variables names to include blank spaces.

What is CamelCase naming?

What is CamelCase? CamelCase is a way to separate the words in a phrase by making the first letter of each word capitalized and not using spaces. It is commonly used in web URLs, programming and computer naming conventions. It is named after camels because the capital letters resemble the humps on a camel's back.

Is CamelCase a TypeScript?

In TypeScript & JavaScript, the camel case convention is used to signify that a token is a variable, function, method, parameter, or property.


1 Answers

  1. Use PascalCase for controllers and for functions which return a constructor function that's supposed to be newed, e.g. var user = new User(). Controllers in Angular are viewed as scope constructor functions--thus the PascalCase.

  2. Controllers should have Controller appended in their name. See http://demisx.github.io/angularjs/2014/09/14/angular-what-goes-where.html for naming examples.

  3. Use camelCase for everything else.

These follow important Javascript conventions that dev around the world got used to.

like image 76
demisx Avatar answered Nov 11 '22 11:11

demisx