我有同样的问题。好像您遇到了我的要点
:-)
至于RC6更新,您应该签出HttpModule源。它显示了最初已被删除的所有提供程序
HTTP_PROVIDERS。我刚刚检查了一下,并提出了以下建议
function getHttp(): Http { let providers = [ { provide: Http, useFactory: (backend: XHRBackend, options: RequestOptions) => { return new Http(backend, options); }, deps: [XHRBackend, RequestOptions] }, BrowserXhr, { provide: RequestOptions, useClass: baseRequestOptions }, { provide: ResponseOptions, useClass: baseResponseOptions }, XHRBackend, { provide: XSRFStrategy, usevalue: new NoopcookieXSRFStrategy() }, ]; return ReflectiveInjector.resolveAndCreate(providers).get(Http);}至于
platform.bootstrapModule(AppModule);
它不是最漂亮的(实际上还不错),但是从[ 这篇文章中]
我发现了一个我什至不知道的可能。看起来您可以在函数 内部 声明模块。
function getAppModule(conf) { @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule ], bootstrap: [ AppComponent ], providers: [ { provide: Configuration, usevalue: conf } ] }) class AppModule { } return AppModule;}下面是我现在用来测试的内容
import { ReflectiveInjector, Injectable, OpaqueToken, Injector } from '@angular/core';import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';import { BrowserModule } from '@angular/platform-browser';import { NgModule } from '@angular/core';import { Observable } from 'rxjs/Observable';import 'rxjs/add/operator/toPromise';import { Http, cookieXSRFStrategy, XSRFStrategy, RequestOptions, baseRequestOptions, ResponseOptions, baseResponseOptions, XHRBackend, BrowserXhr, Response} from '@angular/http';import { AppComponent } from './app.component';import { Configuration } from './configuration';class NoopcookieXSRFStrategy extends cookieXSRFStrategy { configureRequest(request) { // noop }}function getHttp(): Http { let providers = [ { provide: Http, useFactory: (backend: XHRBackend, options: RequestOptions) => { return new Http(backend, options); }, deps: [XHRBackend, RequestOptions] }, BrowserXhr, { provide: RequestOptions, useClass: baseRequestOptions }, { provide: ResponseOptions, useClass: baseResponseOptions }, XHRBackend, { provide: XSRFStrategy, usevalue: new NoopcookieXSRFStrategy() }, ]; return ReflectiveInjector.resolveAndCreate(providers).get(Http);}function getAppModule(conf) { @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule ], bootstrap: [ AppComponent ], providers: [ { provide: Configuration, usevalue: conf } ] }) class AppModule { } return AppModule;}getHttp().get('/app/config.json').toPromise() .then((res: Response) => { let conf = res.json(); platformBrowserDynamic().bootstrapModule(getAppModule(conf)); }) .catch(error => { console.error(error) });


