如何在 index.html 中为 Angular 6 使用环境变量 [英] How to use environment variable in index.html for Angular 6

查看:50
本文介绍了如何在 index.html 中为 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
 });

问题是,appIdstate 的值会根据环境(开发/测试/生产)而变化.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆