Ionic 2 RC0和Angular 2构建android的最新错误(ngc:错误:静态解析符号值时遇到错误)

时间:2016-10-12 14:29:49

标签: android angular typescript compilation ionic2

使用ionic build android命令

构建android时出现错误

ngc:错误:静态解析符号值时遇到错误。引用本地(非导出)符号“字典”。考虑导出符号(原始.ts文件中的位置14:8),解析符号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%通过转换工作

4 个答案:

答案 0 :(得分:2)

我找到了解决方法。

您不必导出词典对象,只需将键更改为静态值即可。

这对我有用:

// 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 },
];

答案 1 :(得分:1)

是的,正如@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 },
];

答案 2 :(得分:0)

好吧,做编译器说的:)。导出你的字典:

export const dictionary : any = {
    [LANG_EN_NAME]: LANG_EN_TRANS,
    [LANG_AR_NAME]: LANG_AR_TRANS,
    [LANG_FR_NAME]: LANG_FR_TRANS
};

答案 3 :(得分:0)

声明[LANG_EN_NAME]的类型:

export const LANG_EN_NAME : string = 'en';

为我工作。