Skip to content

Commit ee8d660

Browse files
committed
added more clarity to service naming
1 parent 87457d7 commit ee8d660

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,15 +1979,19 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
19791979
function AvengersController() { }
19801980
```
19811981
1982-
### Factory Names
1982+
### Factory and Service Names
19831983
###### [Style [Y125](#style-y125)]
19841984
1985-
- Use consistent names for all factories named after their feature. Use camel-casing for services and factories. Avoid prefixing factories and services with `$`.
1985+
- Use consistent names for all factories and services named after their feature. Use camel-casing for services and factories. Avoid prefixing factories and services with `$`. Only suffix service and factories with `Service` when it is not clear what they are (i.e. when they are nouns).
19861986
19871987
*Why?*: Provides a consistent way to quickly identify and reference factories.
19881988
19891989
*Why?*: Avoids name collisions with built-in factories and services that use the `$` prefix.
19901990
1991+
*Why?*: Clear service names such as `logger` do not require a suffix.
1992+
1993+
*Why?*: Service names such as `avengers` are nouns and require a suffix and should be named `avengersService`.
1994+
19911995
```javascript
19921996
/**
19931997
* recommended
@@ -2001,6 +2005,26 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
20012005
function logger() { }
20022006
```
20032007
2008+
```javascript
2009+
/**
2010+
* recommended
2011+
*/
2012+
2013+
// credit.service.js
2014+
angular
2015+
.module
2016+
.factory('creditService', creditService);
2017+
2018+
function creditService() { }
2019+
2020+
// credit.service.js
2021+
angular
2022+
.module
2023+
.service('customersService', customersService);
2024+
2025+
function customersService() { }
2026+
```
2027+
20042028
### Directive Component Names
20052029
###### [Style [Y126](#style-y126)]
20062030

0 commit comments

Comments
 (0)