我正在将我的Angular2代码迁移到RC5,无法弄清楚如何连接我的异常处理。在RC4中,它是Main.ts中引导过程的一部分:
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:)
答案 0 :(得分: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 ]
})