I있는 클래스를 확장 BaseRequestOptions
다음 코드는 I this.serviceA
참조하면2 분사 각도 서비스 (BaseRequestOptions)
import { Injectable } from '@angular/core';
@Injectable()
export class AppRequestOptions extends BaseRequestOptions {
constructor(private serviceA:ServiceA) {
super();
}
merge(options?: RequestOptionsArgs): RequestOptions {
console.log(this.serviceA);
//this.serviceA.myCustomMethod();
return super.merge(options);
}
}
값 undefined
이다. 동일한 서비스를 다른 서비스/구성 요소에 주입하면 예상대로 작동합니다. 여기
import { Injectable } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { APP_ROUTER_PROVIDERS } from './routes';
import { HTTP_PROVIDERS, BaseRequestOptions, RequestOptions, RequestOptionsArgs, Headers } from '@angular/http';
import { ServiceA } from './ServiceA';
@Injectable()
export class AppRequestOptions extends BaseRequestOptions {
constructor(private serviceA:ServiceA) {
super();
}
merge(options?: RequestOptionsArgs): RequestOptions {
console.log(this.serviceA);
//this.serviceA.myCustomMethod();
return super.merge(options);
}
}
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS,
HTTP_PROVIDERS,
ServiceA,
{ provide: RequestOptions, useClass: AppRequestOptions }
]).catch(err => console.error(err));
ServiceA
declaretion :
import { Injectable } from '@angular/core';
@Injectable()
export class ServiceA {
myCustomMethod() {
}
}
내가 각도 버전 을 사용하고 2.0.0-rc.4
나는 확실하지 않다 나는 클래스를 확장하고 그것을 @Injectable()
으로 표시했기 때문에 그것이 맞습니까?
내가 선택하고 내가 찾을 수있는 유일한 관련 질문은 다음과 같습니다가 오픈 관련이 같은
Inject service inside a service inside a service in my Angular 2 application
Angular 2: Inject Service to another service. (No provider error)
UPDATE
보인다 버그 : https://github.com/angular/angular/issues/8925
의 버전 Angular2 당신이 사용합니까? –
@ThierryTemplier 2.0.0-rc.4를 사용 중입니다. –
AppRequestOptions이 @Injectable이 아닙니다. – estus