| Start |
|---|
| Example service services/my.service.ts The service provider registration in the bootstrap method will make the service available globally. main.ts In version RC5 global service provider registration can be done inside the module file. In order to get a single instance of your service for your whole application the service should be declared in the providers list in the ngmodule of your application. app_module.ts Usage in components/my.component.ts Alternative approach to register application providers in application components. If we add providers at component level whenever the component is rendered it will create a new instance of the service. |
| Example with Promise.resolve services/my.service.ts
components/my.component.ts |
| Testing a Service Given a service that can login a user: It can be tested like this: |
Read Article
https://develop.horje.com/learn/1434/reference