Angular comes with different types of services. Each one with its own use cases.
All of these services are singletons. You probably want to use Factory all the time.
constant
)someFunction
is called when the name
service is instantiated and should return an object$delegate
is the service instanceapp.config(function($provide) {
$provide.decorator('serviceToBeDecorated', function($delegate) {
// modify $delegate by adding functions etc.
return $delegate;
});
});
| | Factory | Service | Value | Constant | Provider |
| can have dependencies | yes | yes | no | no | yes |
| uses type friendly injection | no | yes | yes* | yes* | no |
| object available in config phase | no | no | no | yes | yes** |
| can create functions | yes | yes | yes | yes | yes |
| can create primitives | yes | no | yes | yes | yes |
(taken from Angular Guide Show archive.org snapshot . Go there for further explanation.)