2016-09-29 6 views
2

Ich habe einen benutzerdefinierten HTTP-Provider erstellt, um HTTP-Fehler an einem Ort in unserer App zu behandeln. In RC4 benutzt ich die App Bootstrap wie so dieses Ziel zu erreichen:Angular2 zum Überschreiben der Klasse

bootstrap(AppComponent, [ 
    APP_ROUTER_PROVIDERS, 
    HTTP_PROVIDERS, 
    provide(HttpErrorService, { useClass: HttpErrorService }), 
    provide(LocationStrategy, { useClass: HashLocationStrategy }), 
    provide(PLATFORM_DIRECTIVES, { useValue: [ROUTER_DIRECTIVES], multi: true }), 
    provide(Http, { 
     useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions, eService: HttpErrorService) => new CustomHttp(xhrBackend, requestOptions, eService), 
     deps: [XHRBackend, RequestOptions, HttpErrorService] 
    }) 
]); 

Wie mache ich etwas ähnliches jetzt, dass ich die Release-Version renne? Kann ich irgendwie in meinem Hauptapp.Modul verwenden?

Dank!

Antwort

2
@NgModule({ 
    bootstrap: [AppComponent], 
    directives: [AppComponent], 
    imports: [BrowserModule, HttpModule, routing], 
    providers: [ 
    {provide: HttpErrorService, useClass: HttpErrorService }, 
    {provide: LocationStrategy, useClass: HashLocationStrategy }, 
    {provide: Http, 
     useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions, eService: HttpErrorService) => new CustomHttp(xhrBackend, requestOptions, eService), 
     deps: [XHRBackend, RequestOptions, HttpErrorService] 
    }] 
]) 
export class AppModule {} 
+1

Sie antwortete sehr ähnliche Frage für mich: http://stackoverflow.com/questions/39286983/how-to-override-http-class-in-rc6 –

+0

Vielen Dank noch einmal! Dies funktionierte das einzige, was ich ändern musste, ist ngModules Eigentum Provider nicht Provider. – cobolstinks

+0

Sorry für den Tippfehler und danke für das Feedback :) –

Verwandte Themen