1

I see in multiple places that functions in AngularJS begin with uppercase (but not always). In JohnPapa's style guide

https://github.com/johnpapa/angularjs-styleguide#named-vs-anonymous-functions

he shows the following. What I don't get is why Dashboard starts with uppercase and logger is lowercase. shouldn't those be the same?

/* recommended */

// dashboard.js
angular
  .module('app')
  .controller('Dashboard', Dashboard);

function Dashboard() { }

// logger.js
angular
  .module('app')
  .factory('logger', logger);

function logger() { }
0

2 Answers 2

1

This is what he says here:

Use consistent names for all controllers named after their feature. Use UpperCamelCase for controllers, as they are constructors.

Why?: UpperCamelCase is conventional for identifying object that can be instantiated using a constructor.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks, just got to that part of the style guide. github.com/johnpapa/angularjs-styleguide#controller-names Is a factory the only thing in angular that is not a constructor? (confused a little here)
Factories/services are singletons, that's probably the login behind John's reasoning. He suggests directives should use prefixed UpperCamelCase.
(I think you mean "logic" and not "login". Not sure how to edit that or if I can)
Ah, mechanical typing, sorry. No, we can't edit comments after 5 minutes, but it's not that relevant to the question.
0

controllers begin with an uppercase and services with a lowercase. Good practice to put include the words controller/service as in:

 angular.module('app', [])
   .controller('DashboardController', [function Dashboard() { 
   }])
   .factory('loggerService', [function (){
   }]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.