Chcę wprowadzić usługę do innej usługi. Nie mam żadnych problemów z wstrzykiwaniem standardowych usług kątowych (Http, itp.), Ale dostaję wyjątek, gdy próbuję wstrzykiwać własne usługi.Wstrzyknij niestandardową usługę w innej usłudze w Angular 2
Przykład:
MyService:
import {Injectable, Inject} from 'angular2/core';
import {AnotherService} from '../../services/another.service';
@Injectable()
export class MyService {
constructor(Inject(AnotherService) private anotherService: AnotherService) {
console.log(this.anotherService.get());
}
}
AnotherService:
import {Injectable} from 'angular2/core';
@Injectable()
export class AnotherService {
constructor() { }
get() { return 'hello'); }
}
Kiedy próbuję użyć MyService mam EXCEPTION: No provider for AnotherService!
Próbowałem została, używając constructor(private anotherService: AnotherService)
, nadal wyrzuca wyjątek.
Dzięki!
Dziękuję bardzo! Teraz działa! Podałem właśnie 'AnotherService' w dostawcach składników. Powinienem uważniej czytać dokumenty. – NoName