angular5负载使用参数

外部脚本,我需要到下一个脚本加载到我的角度应用angular5负载使用参数

<script src="https://maps.googleapis.com/maps/api/js?key={{google_key}}&libraries=places&language=DE_de"></script> 

正如我知道我可以把全球JS来.angular-cli.json(不适用于外部脚本工作)或index.html,但我如何添加参数(google_key)?

回答:

用于index.html中动态脚本的更快速的解决方案是通过ID引用它和设定从app.component.ts src属性:

googleApi = `https://maps.googleapis.com/maps/api/js?key= 

${environment.google_key}&libraries=places&language=DE_de`

constructor(@Inject(DOCUMENT) private document: any) {}

ngOnInit() {

this.document.getElementById('theId').setAttribute('src', this.googleApi)

}

但是,正如在评论建议的,在这种情况下将它作为构建过程的一部分可能是更好的解决方案。

以上是 angular5负载使用参数 的全部内容, 来源链接: utcz.com/qa/262262.html

回到顶部