如何在 index.html 中为 Angular 6 使用环境变量 [英] How to use environment variable in index.html for Angular 6
问题描述
我使用 angular6,在我的项目中,我使用 Facebook 帐户工具包进行移动验证.
I am using angular6, in my project I am using Facebook Account Toolkit for mobile verification purpose.
我需要使用以下代码在 index.html 文件中初始化 Account 工具包.
I need to initialise Account toolkit in index.html file using following code.
AccountKit.init({
appId:"XX",
state:"xx",
version:"v1.2",
fbAppEventsEnabled:true,
debug:true
});
问题是,appId 和 state 的值会根据环境(开发/测试/生产)而变化.
The problem is, values for appId and state change depending on environment (development/test/production).
如何在 index.html
文件中使用环境变量.
How can I use environment variables in index.html
file.
如果有人有角度 6 的解决方案,请告诉我.
Please let me know if anyone has a solution for angular 6.
提前致谢.
推荐答案
您应该创建 index.html 的副本并将其命名为 index.someenv.html
.然后在你的 angular.json 中的环境配置设置文件替换:
You should create copy of index.html and name it index.someenv.html
.
Then in your angular.json in environment configuration setup file replacement:
"fileReplacements": [
{
"replace": "src/index.html",
"with": "src/index.someenv.html"
}
]
运行构建时,angular cli 将替换这些文件
The angular cli will replace these files when you run your build
这篇关于如何在 index.html 中为 Angular 6 使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!