【发布时间】:2020-07-20 10:53:15
【问题描述】:
我正在开发一个使用外部 JavaScript 库的 Angular 应用程序:
<-- the end of the body element -->
<div id="webapps-sidepanel"></div>
<script src="./assets/js/tecportalapps.js"></script>
<script>
$select('#webapps-sidepanel').getWebapps(localStorage.getItem('TMP_username'));
</script>
</body>
一切正常,但现在本地存储变量名称已更改,我需要使用位于 environment.ts 文件中的环境名称:
export const environment = {
production: true,
*envName*: 'PROD',
};
所以我需要使用这样的东西:
$select('#webapps-sidepanel').getWebapps(localStorage.getItem('TMP_*envName*'));
这可能吗? 欢迎任何关于我如何实现这一目标的想法。也许我可以从 app.component.ts 调用 $select?
【问题讨论】:
-
你的意思是像
localStorage.getItem('TMP_' + environment.envName)? -
@Lain,是的,但是如果我想这样使用它,我会收到此错误:未捕获的 ReferenceError:未定义环境
-
好吧,如果你想使用它,你必须在某处/以某种方式定义/包含它
标签: javascript angular typescript angular8