【问题标题】:How to define "base href " dynamically in Angular 8 application from index.html?如何从 index.html 在 Angular 8 应用程序中动态定义“base href”?
【发布时间】:2020-04-05 01:12:20
【问题描述】:

如何在 Angular 8 应用程序中从 index.html 动态定义“base href”?

之前我用--base-href,现在不支持了。

【问题讨论】:

  • 据我从文档中可以看出,-base-href 仍然有效.. 它不是在您的 dist 文件夹中的 index.html 中设置它吗?

标签: angular angular-cli base-url angular-cli-v8


【解决方案1】:

您可以通过脚本设置属性并在NgModule中获取来动态设置base href。

  //index.html
    <script>
      window['base-url'] = window.location.pathname;
    </script>

在你的模块中你需要使用

@NgModule({
  providers: [{provide: APP_BASE_HREF, useValue: window['base-url]}]
})

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多