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

查看:713
本文介绍了如何在Angular 6中使用index.html中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular6,在我的项目中,我正在使用Facebook Account Toolkit进行移动验证。

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 文件。

请让我知道是否有人对角度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"
    }
]

在运行构建时,角度cli将替换这些文件

The angular cli will replace these files when you run your build

这篇关于如何在Angular 6中使用index.html中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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