angular2 升级后静态解析符号值时出错

标签 angular angular-cli

我已经升级到最新的 angular cli,现在我得到这个错误:

Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol 'dictionary'. Consider exporting the symbol (position 12:7 in the original .ts file), resolving symbol TRANSLATION_PROVIDERS in C:/xampp/htdocs/milesofmusic/src/app/translate/translation.ts, resolving symbol AppModule in C:/xampp/htdocs/milesofmusic/src/app/app.module.ts, resolving symbol AppModule in C:/xampp/htdocs/milesofmusic/src/app/app.module.ts

它引用的代码是这样的:

// all traslations
const dictionary = {
    [LANG_EN_NAME]: LANG_EN_TRANS,
    [LANG_HE_NAME]: LANG_HE_TRANS,
};

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

在我的应用程序模块中导入 从 './translate/translation' 导入 { TRANSLATION_PROVIDERS }; 并将它放在提供者数组中

如何解决?

最佳答案

const dictionary  = {
    [LANG_EN_NAME]: LANG_EN_TRANS,
    [LANG_FR_NAME]: LANG_FR_TRANS,

};

我也遇到同样的错误,所以做一件事:直接写语言值而不是括号。

const dictionary  = {
    "en-US": LANG_EN_TRANS,
    "fr-FR": LANG_FR_TRANS,
};

享受快乐编码

关于angular2 升级后静态解析符号值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41831235/

相关文章:

javascript - Angular 2 - 将组件动态创建/注入(inject)到 *ngFor 循环内的特定元素中

javascript - Angular 5 ngHide ngShow [隐藏] 不工作

Angular 路由器 : (TAB like) navigate - how to change URL without running ngOnInit again

angular - 如何在 Angular Cli 应用程序中包含 Google Analytics

angular - 如何将 yarn 设置为 Angular CLI 的默认 packageManager?我得到 "Cannot read property ' 值为 null”

angular - 嵌套 formGroup 将对象绑定(bind)到单选按钮

angular - 与可观察对象并行读取文件

docker - 即使在 docker 构建镜像时安装了 angular-cli ng 命令,也未找到该命令

node.js - ng 不被识别为内部或外部命令。 Jenkins + 角度 CLI

html - Angular CLI 组件和指令 CSS/SASS 属性和变量