1

请帮我。我必须将 index.html 中“data-smartedit-allow-origin”的硬编码值替换为应该使用站点配置服务检索的值。

通过调用此服务的方法,我可以获得应该用于“data-smartedit-allow-origin”的值。

您对如何将“data-smartedit-allow-origin”硬编码值替换为服务返回的值有任何想法吗?(如果您需要更多信息,请告诉我,我会提供)

索引.html:

<!DOCTYPE html>
<html lang="en">
 <head>
 ...
   <script
      id="smartedit-injector"
      src="webApplicationInjector.js"
      data-smartedit-allow-origin="localhost:9002"
   ></script>
 </head>
  <body>
  ...
  </body>
</html>

服务:

@Injectable({
  providedIn: 'root'
})
export class SiteConfigurationDetailsService {
  constructor(
    private readonly siteConfigurationService: siteConfigurationService
  ) {}

  public getStringValueForKey(key: string): Observable<string> {
    return this.siteConfigurationService.getConfigurationByKey(key).pipe(
      map(result => {
        return result.value.value;
      })
    );
  }

}
4

1 回答 1

0

您可以尝试通过 winref 或 renderer2 生成脚本,而不是尝试替换 index.html 中的值。

首先,您需要删除硬编码脚本。其次,在组件中,创建一个函数,该函数创建一个脚本元素并使用相同的值填充它,但您将data-smartedit-allow-origin使用服务返回的值填充该值。最后,在您的构造函数或任何 Angular 的生命周期钩子中调用它,以便将其注入头部或身体。

于 2020-05-12T06:32:16.707 回答