Setting services (Injectables)
Singleton services for easy data manipulation
Overview
Service is a singleton class instance which able to be used by any class using injection.
Defining class as a service
For setting class as a service the class must be decorated with the @Injectable()
decorator, this will set the class as singleton.
The service need to be set on the module services array:
later we will be able to inject the service instance.
Service constructor cannot be defined with any arguments that are not injectable.
Injection types and aliasing
Overview
Using the module services we are able to define singleton services, constant values and factories for easy injection.
The module services support more informative data structure
Injection remains the same for all types
Examples
Singleton
Useful for getting the same instance of a class
Factory
Useful for getting different instances of the same class
Constant
Useful for services instances (Redis, Socket e.g.) and configuration values
Last updated