app.module.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* eslint-disable import/order */
  2. /* eslint-disable import/no-duplicates */
  3. import { HttpClient, HttpClientModule } from '@angular/common/http';
  4. import { APP_INITIALIZER, Injector, LOCALE_ID, NgModule, Type } from '@angular/core';
  5. import { BrowserModule } from '@angular/platform-browser';
  6. import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  7. import { NzMessageModule } from 'ng-zorro-antd/message';
  8. import { NzNotificationModule } from 'ng-zorro-antd/notification';
  9. import { Observable } from 'rxjs';
  10. // #region default language
  11. // Reference: https://ng-alain.com/docs/i18n
  12. import { default as ngLang } from '@angular/common/locales/zh';
  13. import { DELON_LOCALE, zh_CN as delonLang } from '@delon/theme';
  14. import { zhCN as dateLang } from 'date-fns/locale';
  15. import { NZ_DATE_LOCALE, NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
  16. const LANG = {
  17. abbr: 'zh',
  18. ng: ngLang,
  19. zorro: zorroLang,
  20. date: dateLang,
  21. delon: delonLang,
  22. };
  23. // register angular
  24. import { registerLocaleData } from '@angular/common';
  25. registerLocaleData(LANG.ng, LANG.abbr);
  26. const LANG_PROVIDES = [
  27. { provide: LOCALE_ID, useValue: LANG.abbr },
  28. { provide: NZ_I18N, useValue: LANG.zorro },
  29. { provide: NZ_DATE_LOCALE, useValue: LANG.date },
  30. { provide: DELON_LOCALE, useValue: LANG.delon },
  31. ];
  32. // #endregion
  33. // #region i18n services
  34. import { ALAIN_I18N_TOKEN } from '@delon/theme';
  35. import { I18NService } from '@core';
  36. const I18NSERVICE_PROVIDES = [
  37. { provide: ALAIN_I18N_TOKEN, useClass: I18NService, multi: false }
  38. ];
  39. // #region
  40. // #region JSON Schema form (using @delon/form)
  41. import { JsonSchemaModule } from '@shared';
  42. const FORM_MODULES = [ JsonSchemaModule ];
  43. // #endregion
  44. // #region Http Interceptors
  45. import { HTTP_INTERCEPTORS } from '@angular/common/http';
  46. import { DefaultInterceptor } from '@core';
  47. import { SimpleInterceptor } from '@delon/auth';
  48. const INTERCEPTOR_PROVIDES = [
  49. // { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true},
  50. { provide: HTTP_INTERCEPTORS, useClass: DefaultInterceptor, multi: true}
  51. ];
  52. // #endregion
  53. // #region global third module
  54. const GLOBAL_THIRD_MODULES: Array<Type<void>> = [];
  55. // #endregion
  56. // #region Startup Service
  57. import { StartupService } from '@core';
  58. export function StartupServiceFactory(startupService: StartupService): () => Observable<void> {
  59. return () => startupService.load();
  60. }
  61. const APP_INIT_PROVIDES = [
  62. StartupService,
  63. {
  64. provide: APP_INITIALIZER,
  65. useFactory: StartupServiceFactory,
  66. deps: [StartupService],
  67. multi: true
  68. }
  69. ];
  70. // #endregion
  71. import { AppComponent } from './app.component';
  72. import { CoreModule } from './core/core.module';
  73. import { GlobalConfigModule } from './global-config.module';
  74. import { LayoutModule } from './layout/layout.module';
  75. import { RoutesModule } from './routes/routes.module';
  76. import { SharedModule } from './shared/shared.module';
  77. import { STWidgetModule } from './shared/st-widget/st-widget.module';
  78. import { ReactiveFormsModule } from '@angular/forms';
  79. @NgModule({
  80. declarations: [
  81. AppComponent
  82. ],
  83. imports: [
  84. BrowserModule,
  85. BrowserAnimationsModule,
  86. HttpClientModule,
  87. GlobalConfigModule.forRoot(),
  88. CoreModule,
  89. SharedModule,
  90. LayoutModule,
  91. RoutesModule,
  92. STWidgetModule,
  93. NzMessageModule,
  94. NzNotificationModule,
  95. ...FORM_MODULES,
  96. ...GLOBAL_THIRD_MODULES,
  97. ReactiveFormsModule
  98. ],
  99. providers: [
  100. ...LANG_PROVIDES,
  101. ...INTERCEPTOR_PROVIDES,
  102. ...I18NSERVICE_PROVIDES,
  103. ...APP_INIT_PROVIDES
  104. ],
  105. bootstrap: [AppComponent]
  106. })
  107. export class AppModule { }