如何将变量数据传递给index.html的angular?

时间:2018-05-24 03:41:16

标签: angular

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

<script>

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

</script>

1 个答案:

答案 0 :(得分:0)

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

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

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