I have two services: AuthService and MonBanquetService, and AuthService depends on MyService. Here is the basic code for these two services:
AuthService.ts:
import {Inject, Injectable} from 'angular2/core'; import {MonBanquetService} from '../monbanquet.service' @Injectable() export class AuthService { public username: string; constructor(protected _monBanquetService: MonBanquetService) {
MonBanquetService.ts
import {Injectable, Component} from 'angular2/core'; import {Http, Headers, Response} from 'angular2/http'; import {Router} from 'angular2/router'; @Injectable() export class MonBanquetService { constructor(public http: Http, private _router: Router) { console.log('MonBanquetServices created'); } }
and I put these two services as providers in boot.ts:
bootstrap(AppComponent, [ ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy}), HTTP_PROVIDERS, MonBanquetService, AuthService ]);
However, when I launch the application, I see two console logs called "MonBanquetServices created". I thought that services should be one-stop, but how are there two copies?
Thanks.
source share