gpt4 book ai didi

Angular 如何动态设置(运行时)--deploy-url?

转载 作者:行者123 更新时间:2023-12-03 16:24:01 32 4
gpt4 key购买 nike

我可以如下动态设置 base-href。

index.html

<script>
window['base-href'] = window.location.pathname;
</script>

app.module.ts
providers: [ 
{ provide: APP_BASE_HREF, useValue: window['base-href'] },
],

这对路由很有效。

它不适用于 Assets 加载

如何设置 Assets ?
--deploy-url 在编译时有效,但我如何在运行时做到这一点?

提到的链接用于路由,而不是用于从 SCSS 文件加载的 Assets (图像等)。

我所有的 http 调用都正常进行

示例: https://domain/<env>/<contexname>/<restcall_URI>
图像从 SCSS 加载不发生

例子:
为获取图像而生成的 URL: https://domain/assets/img/xyz.jpg
所需网址: https://domain/<env>/<contexname>/assets/img/xyz.jpg
如何告诉 angular 使用所需的 URL 获取图像

最佳答案

我希望从 CDN 提供 Angular 文件。最终将此代码添加到 main.ts:

declare let __webpack_public_path__: any;
__webpack_public_path__ = window['cdnUrl'];


在你的 index.html 你可以设置 cdnUrl动态地
window.cdnUrl = 'https://...';

关于Angular 如何动态设置(运行时)--deploy-url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54818238/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com