import zh from '@angular/common/locales/zh'; import { BrowserModule } from '@angular/platform-browser'; import { NgModule, Provider, APP_INITIALIZER } from '@angular/core'; import { registerLocaleData } from '@angular/common'; import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; import { RouteReuseStrategy } from '@angular/router'; import { RhRouteReuseStrategy, RhDefaultInterceptor, RhInterfaceInterceptor, RhCoreModule, RhNavigatorService, RhFactoryInterceptor, RhThrottleInterceptor } from 'rh-base/core'; import { RhCustomizeSelectorDatas } from 'rh-base/model'; import { NzModalModule } from 'ng-zorro-antd/modal'; import { NzMessageModule } from 'ng-zorro-antd/message'; import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; import { InteractionService, StartupService } from '@core'; import { AppRoutingModule } from './app-routing.module'; import { NzCodeEditorModule } from 'ng-zorro-antd/code-editor'; import { CUSTOMIZE_SELECTOR_DATA } from 'rh-base/model'; import { NZ_I18N, zh_CN } from 'ng-zorro-antd/i18n'; import { environment } from '@env/environment'; import { RhMainModule } from './routes/main/lcdp-main/main.module'; registerLocaleData(zh); function StartupServiceFactory(startupService: StartupService) { return () => { return startupService.load(environment.production, '../../assets/temp/app-config.json'); }; } /** * 初始化交互:`MsgHelper` */ function interactionServiceFactory(interactionSer: InteractionService) { return () => { return interactionSer.initInteractionConfig(); }; } /** 程序初始化前获取配置信息等工作 */ const APPINIT_PROVIDES: Provider[] = [ StartupService, { provide: APP_INITIALIZER, useFactory: StartupServiceFactory, deps: [StartupService], multi: true }, InteractionService, { provide: APP_INITIALIZER, useFactory: interactionServiceFactory, deps: [InteractionService], multi: true } ]; /** 路由复用提供商 */ const APP_ROUTEREUSE_PROVIDERS: Provider[] = [ { provide: RouteReuseStrategy, useClass: RhRouteReuseStrategy } ]; /** 拦截器提供商 */ const INTERCEPTOR_PROVIDERS: Provider[] = [ { provide: HTTP_INTERCEPTORS, useClass: RhThrottleInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: RhDefaultInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: RhInterfaceInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: RhFactoryInterceptor, multi: true } ]; /** 自定义通用selector提供商 */ const BASE_SELECTOR_DATA_PROVIDERS: Provider[] = [ { provide: CUSTOMIZE_SELECTOR_DATA, useValue: [RhCustomizeSelectorDatas], multi: true } ]; @NgModule({ declarations: [AppComponent], imports: [ HttpClientModule, RhCoreModule, BrowserModule, FormsModule, BrowserAnimationsModule, NzModalModule, NzMessageModule, NzCodeEditorModule, RhMainModule, AppRoutingModule ], providers: [ ...APPINIT_PROVIDES, ...APP_ROUTEREUSE_PROVIDERS, ...INTERCEPTOR_PROVIDERS, ...BASE_SELECTOR_DATA_PROVIDERS, { provide: NZ_I18N, useValue: zh_CN }, RhNavigatorService ], bootstrap: [AppComponent] }) export class AppModule {}