Angular JS naming conventions ($, camelCase and PascalCase)

后端 未结 3 915
礼貌的吻别
礼貌的吻别 2020-12-15 17:08

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

3条回答
  •  情书的邮戳
    2020-12-15 17:41

    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.

提交回复
热议问题