Angular 用方法调用返回的值替换index.html中的硬编码值

Angular 用方法调用返回的值替换index.html中的硬编码值,angular,typescript,hybris,spartacus-storefront,Angular,Typescript,Hybris,Spartacus Storefront,请帮帮我。 我必须将index.html中“data smartedit allow origin”的硬编码值替换为应该使用站点配置服务检索的值 通过调用此服务的一个方法,我可以获得“data smartedit allow origin”应该使用的值 您知道如何用服务返回的值替换“data smartedit allow origin”硬编码值吗? (如果您需要更多信息,请告诉我,我会提供) index.html: <!DOCTYPE html> <html lang="en

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

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

您知道如何用服务返回的值替换“data smartedit allow origin”硬编码值吗? (如果您需要更多信息,请告诉我,我会提供)

index.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;
      })
    );
  }

}

...
...
服务:

<!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;
      })
    );
  }

}
@可注入({
providedIn:'根'
})
导出类SiteConfigurationDetails服务{
建造师(
专用只读siteConfigurationService:siteConfigurationService
) {}
public getStringValueForKey(键:string):可观察{
返回此.siteConfigurationService.getConfigurationByKey(key).pipe(
映射(结果=>{
返回result.value.value;
})
);
}
}

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

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

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

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