【发布时间】:2017-01-05 15:50:15
【问题描述】:
出于某种原因,我不想使用构造函数(private http: Http) DI。
看了https://angular.io/docs/ts/latest/api/http/index/Http-class.html
试过了
const injector = ReflectiveInjector.resolveAndCreate([
BaseRequestOptions,
XHRConnection,
{
provide: Http,
useFactory: (backend, defaultOptions) => new Http(backend, defaultOptions),
deps: [XHRConnection, BaseRequestOptions]
}
]);
this.http = injector.get(Http);
错误提示
原始异常:无法解析“XHRConnection”的所有参数(?,?,?)。确保所有参数都使用 Inject 进行修饰或具有有效的类型注释,并且 'XHRConnection' 使用 Injectable 进行修饰。
【问题讨论】:
标签: http angular dependency-injection