Services

Services are singletons ( Style 07-01)

  • Use services as singletons within the same injector. Use them for sharing data and funcionality.

Single responsability (Style 07-02)

  • create services with a single responsibility that is encapsulated by its context.

Providing a services (Style 07-03)

  • Provide services to the Angular injector at the top-most component where they will be shared.

Use the @Injectable() class decorator (Style 07-04)

  • Use the @Injectable class decorator instead of the @Inject parameter decorator when using types as tokens for the dependencies of a services.

@Injectable()
export class HeroArena {
  constructor(
    private heroService: HeroService,
    private http: Http) {}
}