使用ionic build android命令构建android时出现错误
ngc: Error:遇到静态解析符号值时出错。对本地(非导出)符号“字典”的引用。考虑导出符号(原始.ts文件中的位置14:8 ),解析symbol TRANSLATION_PROVIDERS
我在translation.ts文件中的代码
export const TRANSLATIONS = new OpaqueToken('translations');
// all traslations
const dictionary : any = {
[LANG_EN_NAME]: LANG_EN_TRANS,
[LANG_AR_NAME]: LANG_AR_TRANS,
[LANG_FR_NAME]: LANG_FR_TRANS
};
// providers
export const TRANSLATION_PROVIDERS : any = [
{ provide: TRANSLATIONS, useValue: dictionary},
];我的app.module.ts代码
import {TRANSLATION_PROVIDERS,TranslatePipe,TranslateService} from './translate';
@NgModule({
declarations: [
MyApp,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
],
providers: [TRANSLATION_PROVIDERS,TranslateService ]
})
export class AppModule {}关于这个问题的任何建议,顺便说一句,当我使用ionic serve命令时,我的项目100%处理事务
发布于 2016-11-17 06:46:40
我找到了解决这个问题的方法。
您不必导出字典对象,只需将键更改为静态值即可。
这对我很有效:
// all translations
const dictionary = {
"en": LANG_EN_TRANS,
"ar": LANG_AR_TRANS,
"fr": LANG_FR_TRANS
};
// providers
export const TRANSLATION_PROVIDERS = [
{ provide: TRANSLATIONS, useValue: dictionary },
];发布于 2017-03-17 14:10:51
是的,正如@welefish在他的回答中所说,不需要导出您的字典对象,您只需将键更改为静态值。
PS:-另一个方法(发布为答案,因为@welefish方法对我不起作用)
let en = LANG_EN_NAME;
let er = LANG_AR_NAME;
let fr = LANG_FR_NAME;
const dictionary : any = {
en: LANG_EN_TRANS,
er: LANG_AR_TRANS,
fr: LANG_FR_TRANS
};
// providers
export const TRANSLATION_PROVIDERS = [
{ provide: TRANSLATIONS, useValue: dictionary },
];发布于 2016-10-12 22:37:20
好的,照编译器说的做:)。导出您的字典:
export const dictionary : any = {
[LANG_EN_NAME]: LANG_EN_TRANS,
[LANG_AR_NAME]: LANG_AR_TRANS,
[LANG_FR_NAME]: LANG_FR_TRANS
};https://stackoverflow.com/questions/40001256
复制相似问题