【问题标题】:How to pass variable data to index.html in angular?如何以角度将变量数据传递给index.html?
【发布时间】:2018-05-24 03:41:16
【问题描述】:

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

<script>

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

</script>

【问题讨论】:

    标签: angular


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 2020-09-18
      • 2016-01-03
      • 2015-09-22
      • 1970-01-01
      • 2017-09-17
      • 2021-09-20
      相关资源
      最近更新 更多