Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 910788e

Browse files
anilgulechapetebacondarwin
authored andcommitted
docs(guide/services): explain services in plain language
See the discussion at http://docs.angularjs.org/guide/dev_guide.services.understanding_services#comment-1002821035 Closes #4055
1 parent 80ab7ea commit 910788e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docs/content/guide/dev_guide.services.understanding_services.ngdoc

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ another service) that depends on the service. Angular's dependency injection su
1111
of the rest. The Angular injector subsystem is in charge of service instantiation, resolution of
1212
dependencies, and provision of dependencies to factory functions as requested.
1313

14+
The purpose of a service factory function is to generate a single object or function that
15+
represents the service to the rest of the application. That object or function will then be
16+
passed as a parameter to any other factory function which specifies a dependency on this service.
17+
18+
Angular factory functions are executed lazily. That is, they are only executed when needed
19+
to satisfy a dependency, and are then executed exactly once for each service. Everything which is
20+
dependent on this service gets a reference to the single instance generated by the service factory.
21+
1422
Angular injects dependencies using "constructor" injection (the service is passed in via a factory
1523
function). Because JavaScript is a dynamically typed language, Angular's dependency injection
1624
subsystem cannot use static types to identify service dependencies. For this reason a dependent
@@ -22,7 +30,6 @@ The Angular web framework provides a set of services for common operations. Like
2230
variables and identifiers, the built-in services always start with `$` (such as `$http` mentioned
2331
above). You can also create your own custom services.
2432

25-
2633
## Related Topics
2734

2835
* {@link di About Angular Dependency Injection}

0 commit comments

Comments
 (0)