app.module.ts 1.92 KB
Newer Older
kunw's avatar
kunw committed
1
import { BrowserModule } from '@angular/platform-browser';
kunw's avatar
kunw committed
2
import { NgModule, APP_INITIALIZER } from '@angular/core';
kunw's avatar
kunw committed
3 4 5 6 7 8 9
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { ClarityModule } from 'clarity-angular';
import { AppComponent } from './app.component';

import { BaseModule } from './base/base.module';
import { HarborRoutingModule } from './harbor-routing.module';
10
import { SharedModule } from './shared/shared.module';
kunw's avatar
kunw committed
11
import { AccountModule } from './account/account.module';
Steven Zou's avatar
Steven Zou committed
12
import { ConfigurationModule } from './config/config.module';
kunw's avatar
kunw committed
13

Steven Zou's avatar
Steven Zou committed
14 15 16 17 18
import { TranslateModule, TranslateLoader, MissingTranslationHandler } from "@ngx-translate/core";
import { MyMissingTranslationHandler } from './i18n/missing-trans.handler';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { Http } from '@angular/http';

19
import { AppConfigService } from './app-config.service';
kunw's avatar
kunw committed
20

Steven Zou's avatar
Steven Zou committed
21
export function HttpLoaderFactory(http: Http) {
Steven Zou's avatar
Steven Zou committed
22
    return new TranslateHttpLoader(http, 'ng/i18n/lang/', '-lang.json');
Steven Zou's avatar
Steven Zou committed
23 24
}

25 26
export function initConfig(configService: AppConfigService) {
    return () => configService.load();
kunw's avatar
kunw committed
27 28
}

kunw's avatar
kunw committed
29 30 31 32 33
@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
34
        SharedModule,
kunw's avatar
kunw committed
35
        BaseModule,
kunw's avatar
kunw committed
36
        AccountModule,
Steven Zou's avatar
Steven Zou committed
37
        HarborRoutingModule,
Steven Zou's avatar
Steven Zou committed
38
        ConfigurationModule,
Steven Zou's avatar
Steven Zou committed
39 40 41 42 43 44 45 46 47 48 49
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: (HttpLoaderFactory),
                deps: [Http]
            },
            missingTranslationHandler: {
                provide: MissingTranslationHandler,
                useClass: MyMissingTranslationHandler
            }
        })
kunw's avatar
kunw committed
50
    ],
51 52 53
    providers: [
        AppConfigService,
        {
kunw's avatar
kunw committed
54 55
        provide: APP_INITIALIZER,
        useFactory: initConfig,
56
        deps: [AppConfigService],
kunw's avatar
kunw committed
57 58
        multi: true
    }],
59
    bootstrap: [AppComponent]
kunw's avatar
kunw committed
60 61 62
})
export class AppModule {
}