2016-08-10 100 views
2

我正在將我的Angular2代碼遷移到RC5,無法弄清楚如何連接我的異常處理。在RC4,它是在Main.ts引導過程的一部分:更改Angular2 RC5 ExceptionHandler?

bootstrap(MyApp, [{provide: ExceptionHandler, useClass: GlobalExceptionHandler}]) 

但現在我們有一個app.module.ts,我不知道如何包含引用的ExceptionHandler並將其指向在GlobalErrorHandler。我的新app.module.ts如下:

import { NgModule } from "@angular/core"; 
import { BrowserModule } from "@angular/platform-browser"; 
import { FormsModule } from "@angular/forms"; 
import { AppComponent } from "./app.component"; 
import { ExceptionHandler } from "@angular/core"; 
import { GlobalErrorHandler } from "./shared/utils/global-error-handler"; 
import { ExceptionApiService } from "./shared/utils/exception-api-service"; 
import { HomeComponent } from "./home/home.component"; 
import { ContentManagementComponent } from "./contentManagement/content-management.component"; 
import { GetContentComponent } from "./getContent/get-content.component"; 
import { AddContentComponent } from "./addContent/add-content.component"; 
import { ErrorComponent } from "./errorPage/error.component"; 
import { appRoutingProviders, APP_ROUTER_PROVIDERS } from "./app.routes"; 
import { APP_PROVIDERS } from "./app.providers"; 

@NgModule({ 
    imports:  [ BrowserModule, FormsModule, APP_ROUTER_PROVIDERS ], 
    declarations: [ AppComponent, HomeComponent,  ContentManagementComponent, GetContentComponent, AddContentComponent, ErrorComponent ], 
    providers: [ appRoutingProviders, APP_PROVIDERS, GlobalErrorHandler, ExceptionApiService ], 
    bootstrap: [ AppComponent ] 
}) 

// How to bootstrap ExceptionHandler and point at GlobalErrorHandler?? 

export class AppModule {} 

任何想法?沒有很多與ExceptionHandling相關的文檔,尤其是RC5 :)

回答

2

與其他提供者類似,您需要將其注入到您的模塊中。

@NgModule({ 
    imports:  [ BrowserModule, FormsModule, APP_ROUTER_PROVIDERS ], 
    declarations: [ AppComponent, HomeComponent,  ContentManagementComponent, GetContentComponent, AddContentComponent, ErrorComponent ], 
    providers: [ appRoutingProviders, APP_PROVIDERS, {provide: ExceptionHandler, useClass: GlobalExceptionHandler}, ExceptionApiService ], 
    bootstrap: [ AppComponent ] 
})