我试图在 Angular 中为不同的环境加载不同的 JS 文件,因为我的 js 文件的前缀不同,我无法将它们保存在本地。
开发中
js file path is http://myproject-dev.com/product.js
所以我的 html 会是这样的
<script src="http://myproject-dev.com/product.js"></script>
产品
js file path is http://myproject.com/product.js
我的 html 是这样的
<script src="http://myproject.com/product.js"></script>
我需要根据环境加载它们,我在 JS 中设置了一个变量来检测环境,但我不知道如何在 html 或 Angular 运行时加载它们。任何提示将不胜感激。谢谢!
最佳答案
使用相对 URL。
相同位置:<script src="product.js"></script>
.
当前位置的子文件夹:<script src="scripts/product.js"></script>
根目录下的子文件夹:<script src="/scripts/product.js"></script>
关于javascript - 就我而言,如何在运行时加载 JS 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27969299/