从这个例子中我在Angular2中有简单的TranslationModule .在一次angular-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 {
}
Run Code Online (Sandbox Code Playgroud)
而翻译
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}
];
Run Code Online (Sandbox Code Playgroud)
尝试将键更改为静态值,例如:
export const dictionary = {
'en': LANG_EN_US_TRANS,
'de': LANG_DE_DE_TRANS
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2577 次 |
| 最近记录: |