我知道我不是唯一有關於這個術語的問題。但這個角色傢伙大約有23個關於這個詞的問題。我嘗試了很多不同的東西。其中一個很重要:我以與@angular/http
(導出裸機功能)相同的方式嘗試。在angular-cli中使用我的模塊:遇到的錯誤靜態解析符號值
事實是:它的工作原理 - 代碼沒有錯誤。但是,當我嘗試導入模塊我得到這個錯誤:
ERROR in Error encountered resolving symbol values statically. Calling function
'TranslatorConfig', function calls are not supported. Consider replacing the
function or lambda with a reference to an exported function, resolving symbol
TranslatorModule.forRoot
當我運行NG發球和這個錯誤將其重新編譯沒有錯誤之後觸摸文件。但是,我試圖建立(ng build -e prod --aot false
)我得到這個錯誤,並停止構建。當我在tsconfig.json中設置"strictMetadataEmit": true
時,我也會遇到這個錯誤。我有一個TranslatorModule.metadata.json
- 這不會是錯誤。
爲什麼它不起作用?這個錯誤信息意味着什麼?什麼是符號值以及爲什麼它必須是靜態的?如何讓它工作?
對於測試,您可以只安裝[email protected]。你可以找到github上的代碼:https://github.com/tflori/angular2-translator/tree/2.0
我剛剛嘗試過這些導出的函數和不同的提供者,如下所示。
export function createTranslatorConfig(config: any = {}) {
return new TranslatorConfig(config);
}
export function createTranslator(translatorContainer: TranslatorContainer, module: string) {
return translatorContainer.getTranslator(module);
}
// ...
export class TranslatorModule {
public static forRoot(config: any = {}, module: string = "default"): ModuleWithProviders {
return {
ngModule: TranslatorModule,
providers: [
{ provide: "TranslatorConfigOptions", useValue: config },
{ provide: TranslatorConfig, useFactory: createTranslatorConfig, deps: [ "TranslatorConfigOptions" ] },
{ provide: "TranslatorModuleName", useValue: module },
{
provide: Translator,
useFactory: createTranslator,
deps: [ TranslatorContainer, "TranslatorModuleName" ],
},
],
};
}
}
結果就是另一條錯誤消息(現「emakeDecorator」的符號NgModule有一個問題:ERROR in Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol NgModule
'{提供:TranslatorConfig,useValue:new TranslatorConfig(config)},'不要在這裏實例化將其移到一個函數中,只需使用'useValue'或useFactory'調用函數 –
?爲什麼?最後但並非最不重要的:我敢肯定它不會工作..我真的嘗試了很多。 – iRaS
消息有一些不同 - 但是正如預期的那樣,它並沒有幫助:'遇到錯誤時遇到靜態解析符號值。調用函數'TranslatorConfig',不支持函數調用。考慮使用對導出函數的引用替換函數或lambda,解析符號createTranslatorConfig' – iRaS