2017-04-13 84 views
1

我在編譯AOT時遇到問題(npm run ngc -p tsconfig-aot.json)。甚至無法理解 我試着更換AOT編譯問題獲取錯誤:遇到的錯誤靜態解析符號值。調用函數'TranslateModule'

TranslateModule.forRoot(TRANSLATE_LOADER) 

export function translateLoader(http: Http): TranslateStaticLoader { 
return new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json"); 
}; 
const TRANSLATE_LOADER: any = { 
provide: TranslateLoader, 
useFactory: translateLoader, 
deps: [Http] 
} 

insted的的

TranslateModule.forRoot({ 
    provide: TranslateLoader, 
    useFactory: (http: Http): TranslateStaticLoader => new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json"), 
    deps: [Http] 
    }) 

,但仍然得到

Error: Error encountered resolving symbol values statically. Calling function 'TranslateModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /home/retacc/dev/src/sbb-ri-erepko/retacc.sbb.ri.erepko.main/src/integrated-workshop/src/app/app.module.ts, resolving symbol AppModule in /home/retacc/dev/src/sbb-ri-erepko/retacc.sbb.ri.erepko.main/src/integrated-workshop/src/app/app.module.ts

我app.module.ts

import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ErrorHandler } from "@angular/core"; 
import { BrowserModule } from "@angular/platform-browser"; 
import { Http, HttpModule } from "@angular/http"; 
import { RouterModule } from "@angular/router"; 
import { combineReducers, StoreModule } from "@ngrx/store"; 
import { ActionReducer } from "@ngrx/store"; 
import { compose } from "@ngrx/core/compose"; 
import { ReactiveFormsModule } from "@angular/forms"; 
import { TranslateStaticLoader, TranslateModule, TranslateLoader, TranslateService } from "ng2-translate/ng2-translate"; 
// import { CommonModule } from '@angular/common'; 

import { JobSearchService } from "./job-selection-search/job-search/job-search.service"; 
import { ContextHttp } from "./common/component/context-http/context-http.service"; 
import { IntegratedWorkshopComponent } from "./integratedWorkshop.component"; 
import { APP_ROUTES } from "./app.routes"; 
import { ScrollTopComponent } from "./common/component/scroll-top/scroll-top.component"; 
import { IWErrorHandler } from "./common/error-handler/iw-error-handler"; 
import { SharedModule } from "./common/shared.module"; 
import { CommonModule } from "./common/common.module" 
import { VehicleInformationModule } from "./vehicle-information/vehicle-information.module"; 
import { CustomerConcernModule } from "./customer-concern/customer-concern.module"; 
import { LocalContentModule } from "./local-content/local-content.module"; 
import { JobSelectionSearchComponentModule } from "./job-selection-search/job-selection-search.component.module"; 
import { JobContentModule } from "./job-content/job-content.module"; 
import { JOB } from "./store/reducer/job.reducer"; 
import { JOB_SELECTION } from "./store/reducer/job-selection.reducer"; 
import { CustomBack } from "./common/util/custom.back"; 
import { HEADER_CONTENT } from "./store/reducer/header-content.reducer"; 
import { ShortTestModule } from "./short-test/short-test.module"; 
import { ASSOCIATED_DOCUMENTS } from "./store/reducer/associated-documents.reducer"; 

export function translateLoader(http: Http): TranslateStaticLoader { 
    return new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json"); 
}; 

const developmentReducer: ActionReducer<any> = compose(
       combineReducers 
)({ JOB_SELECTION, JOB, HEADER_CONTENT, ASSOCIATED_DOCUMENTS }); 

export function reducer(state: any, action: any) { 
    return developmentReducer(state, action); 
}; 

const TRANSLATE_LOADER: any = { 
    provide: TranslateLoader, 
    useFactory: translateLoader, 
    deps: [Http] 
} 

// export { IntegratedWorkshopComponent, ScrollTopComponent }; 

@NgModule({ 
    imports: [ 
     // angular modules 
     BrowserModule, 
     ReactiveFormsModule, 
     // no forms module, import it in feature modules 
     // according to ng documentation import http module ONLY in app module (has providers) 
     HttpModule, 
     StoreModule.provideStore(reducer), 
     RouterModule.forRoot(APP_ROUTES, { useHash: true }), 
     TranslateModule.forRoot(TRANSLATE_LOADER), 
     // lib modules 
     // TranslateModule.forRoot({ 
     // provide: TranslateLoader, 
     // useFactory: (http: Http): TranslateStaticLoader => new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json"), 
     // deps: [Http] 
     // }), 
     SharedModule, 
     // // app-common and app-shared modules with additional providers 
     CommonModule.forRoot(), 
     // // app-feature modules 
     // CommonModule, 
     JobContentModule, 
     JobSelectionSearchComponentModule, 
     VehicleInformationModule, 
     CustomerConcernModule, 
     LocalContentModule, 
     ShortTestModule 
    ], 
    declarations: [ 
     IntegratedWorkshopComponent, 
     ScrollTopComponent 
    ], 
    providers: [ 
     // provideStore(
     // compose(
     //  combineReducers 
     // )({ JOB_SELECTION, JOB, HEADER_CONTENT, ASSOCIATED_DOCUMENTS }) 
     //), 
     TranslateService, { provide: TranslateLoader, useFactory: translateLoader, deps: [Http] }, 
     JobSearchService, 
     ContextHttp, 
     CustomBack, 
     { provide: ErrorHandler, useClass: IWErrorHandler } 
    ], 
    bootstrap: [IntegratedWorkshopComponent], 
    schemas: [CUSTOM_ELEMENTS_SCHEMA] 
}) 
export class AppModule { } 

回答

0

您正在使用我是da功能: useFactory: (http: Http): TranslateStaticLoader => new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json")

將此代碼替換爲您的代碼。

export function translateLoader(http: Http): TranslateStaticLoader { 

    return new TranslateStaticLoader(http, (window as any).rest + "textmodules", ".json"); 

}; 

TranslateModule.forRoot({ 
    provide: TranslateLoader, 
    useFactory: (translateLoader), 
    deps: [Http] 
}) 
+0

仍然有相同的錯誤@harinim –

+0

您是否刪除了const TRANSLATE_LOADER? – harinim

+0

如果仍然不起作用,請嘗試從提供程序中刪除TranslateService或在導出中添加TranslateModule。 – harinim

相關問題