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?
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.
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? 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.
In TypeScript & JavaScript, the camel case convention is used to signify that a token is a variable, function, method, parameter, or property.
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.
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.
Use camelCase
for everything else.
These follow important Javascript conventions that dev around the world got used to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With