Angular 2 Error在静态解析符号值时遇到错误

时间:2017-01-30 09:55:00

标签: angular

我在this example的Angular2中有简单的TranslationModule。现在,在更新了角度cli之后,我得到了上述错误,但我不知道我必须在此处更改:

import {NgModule} from "@angular/core";
import {TranslatePipe} from "./translate.pipe";
import {TRANSLATION_PROVIDERS} from "./translations";
import {TranslateService} from "./translate.service";

@NgModule({
  declarations: [
    TranslatePipe
  ],
  providers: [
    TRANSLATION_PROVIDERS,
    TranslateService
  ],
  exports: [
    TranslatePipe
  ]
})
export class TranslateModule {
}

和translation.ts

import {OpaqueToken} from '@angular/core';

// import translations
import {LANG_EN_US_NAME, LANG_EN_US_TRANS} from './lang-en_US';
import {LANG_DE_DE_NAME, LANG_DE_DE_TRANS} from './lang-de_DE';

// translation token
export const TRANSLATIONS = new OpaqueToken('translations');

// default language
export const DEFAULT_LANG = "en_US";

// all translations
export const dictionary = {
  [LANG_EN_US_NAME]: LANG_EN_US_TRANS,
  [LANG_DE_DE_NAME]: LANG_DE_DE_TRANS
};

// providers
export const TRANSLATION_PROVIDERS = [
  {provide: TRANSLATIONS, useValue: dictionary}
];

2 个答案:

答案 0 :(得分:4)

尝试将键更改为静态值,如:

export const dictionary = {
  'en': LANG_EN_US_TRANS,
  'de': LANG_DE_DE_TRANS
};

答案 1 :(得分:0)

AoT不支持ES6属性访问器。查看AoT Do's and Don'ts