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
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.
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
Also, regarding camelCase, the docs say to use camelCase.
Angular uses name-with-dashes for attribute names and camelCase for the corresponding directive name
http://docs.angularjs.org/tutorial/step_00
We can filter Text in CamelCase using following code
app.filter('camelCase', function(){
var camelCaseFilter = function(input){
var words = input.split(' ');
for (var i = 0, len = words.length; i < len; i++)
words[i] = words[i].charAt( 0 ).toUpperCase() + words[i].slice(1);
return words.join(' ');
};
return camelCaseFilter;
});