我正在构建一个允许您编辑地图的应用程序,编辑器具有带有 Agm 地图模块的谷歌地图,用户的最终结果是一个 iframe,其地图嵌入到他的网页中。我正在为编辑器使用该模块,并在 app.module.ts 中使用我的 API 密钥导入它。
import { AgmCoreModule } from '@agm/core';
...
imports: [
...
AgmCoreModule.forRoot({
apiKey: 'YOUR_KEY'
})
]
iframe 将是一个使用相同后端的独立 Angular 应用程序。我需要将从数据库中获取的用户的 API 密钥,但我不知道如何在 Angular 中构建这部分,似乎它使用 api 密钥创建构建,是否可以这样做以某种方式在运行时修改密钥?我已经看到它是在 jQuery 中完成的。可以从 script 标签或 vanilla js 中的代码中获取它,例如:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
在最后一个例子中,它可以很容易地完成,谢谢