XHRBackend
클래스의 래퍼를 만들려고했는데, 가장 바깥 쪽에서 제공된 모든 서비스를 성공적으로 만들고 사용할 수 있었지만 AppComponent
패키지 할 수 없습니다. 실제 서비스 자체의 공급자. 구성 요소 생성자에 클래스를 삽입하고 있지만 아무것도 망가 뜨릴 것이라고 상상할 수는 없습니다.Angular2 - 상수로 공급자 목록이 작동하지 않음
현재 AppComponent
코드 :
import {HTTP_PROVIDERS, Http, ConnectionBackend, RequestOptions} from "@angular/http";
import {ROUTER_DIRECTIVES} from "@angular/router";
import {XHRBackendWrapper} from 'backendwrapper.services';
@Component({
selector: 'app',
template: './app.component.html',
directives: [ROUTER_DIRECTIVES],
providers: [
HTTP_PROVIDERS,
provide(Http, {
useFactory: (xhrBackend: ConnectionBackend, requestOptions: RequestOptions) => new Http(xhrBackend, requestOptions),
deps: [XHRBackendWrapper, RequestOptions]
}),
XHRBackendWrapper
]
})
export class AppComponent {
constructor(xhrBackend: XHRBackendWrapper){
}
}
원하는 AppComponent
코드 :
import {HTTP_PROVIDERS} from "@angular/http";
import {ROUTER_DIRECTIVES} from "@angular/router";
import {BACKEND_PROVIDERS, XHRBackendWrapper} from 'backendwrapper.services';
@Component({
selector: 'app',
template: './app.component.html',
directives: [ROUTER_DIRECTIVES],
providers: [
HTTP_PROVIDERS,
/** THIS IS THE ONLY DIFFERENCE HERE!!! ***/
BACKEND_PROVIDERS
]
})
export class AppComponent {
constructor(xhrBackend: XHRBackendWrapper){
}
}
백엔드 래퍼에서 일정한 수출 희망 : 나는 내가 얻을이 작업을 수행하려고
export const BACKEND_PROVIDERS = [
provide(Http, {
useFactory: (xhrBackend: ConnectionBackend, requestOptions: RequestOptions) => new Http(xhrBackend, requestOptions),
deps: [XHRBackendWrapper, RequestOptions]
}),
XHRBackendWrapper
];
내 콘솔에 나타나는 One or more of providers for "AppComponent" were not defined
오류 b 질문 : XHRBackendWrapper
을 찾을 수 없습니다. 내가 여기서 무엇을 놓치고 있니?
내가이 질문이 너무 큰 만들 것 때문에 모든 코드를 게시하지만, 도움이된다면, 이것은 XHRBackendWrapper에 대한 일반적인 생각이다 할 수 없습니다 completly 확인
@Injectable()
export class XHRBackendWrapper extends ConnectionBackend {
constructor(private _xhrBackend: XHRBackend)
{
super();
}
createConnection(request: Request)
{
return this._xhrBackend.createConnection(request);
}
}