如何以角度将变量数据传递到index.html? [英] How to pass variable data to index.html in angular?

查看:55
本文介绍了如何以角度将变量数据传递到index.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将动态脚本插入index.html的开头,但是该脚本包含一个变量.参见下文-变量应插入由{{shopName}}指示的shopOprigin中,该变量通过app.component.ts中的ActivatedRoute获得.

I am trying to insert a dynamic script into the head of index.html, however the script contains a variable. See below - The variable should be inserted into shopOprigin indicated by {{shopName}} which is obtained through ActivatedRoute in app.component.ts

<script>

ShopifyApp.init({
      shopOrigin: 'https://{{shopName}}.myshopify.com'
    });

</script>

推荐答案

您不应该在HTML内部使用 environment 变量.相反,您应该尝试的是将ShopifyApp库导入到 index.html 的开头,然后调用该函数:

You shouldn't be looking to use the environment variables inside of you HTML. What you should try instead is after importing the ShopifyApp library into the head of your index.html to then call the function:

ShopifyApp.init({
   shopOrigin: 'https://' + environment.shopName + '.myshopify.com'
});

进入您的 app.module.ts main.ts (在引导应用程序之前).在这两个文件中,您都可以导入和使用 environment 变量.

Into maybe your app.module.ts or main.ts (before you bootstrap your application). In both files you can import and use your environment variables.

这篇关于如何以角度将变量数据传递到index.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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