angular - Angular2 运行时如何包含脚本标签?

标签 angular

如何在 Angular2 页面 View 中包含这个外部 java 脚本库。

我想包括这个

 <!-- google maps javascript -->
 <script src="//maps.googleapis.com/maps/api/js?key=#######&sensor=true"></script>

所以当这个页面在 View 中时,这个库被加载并开始工作。

最佳答案

你不能。
出于安全原因,Angular 处理器会删除模板文件中的所有脚本标记。


备选方案:

  • 将您的脚本放入 index.html
  • 使用 import 'path/to/file' 将其直接导入到您的组件 .ts 文件中。

关于angular - Angular2 运行时如何包含脚本标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41124575/

相关文章:

javascript - 无法完成实时搜索查询

Angular 6 跟进 : [attr. 禁用] 选项值禁用所有条目

angular - 没有路由的组件的延迟加载路由。 Angular 2

angular - 在 Angular 中,*ngFor ="let item from list | async"是什么意思?

javascript - 自动缓存新补丁

css - Bootstrap 4 : How do i push the Item C to the bottom in mobile view

angular - NullInjectorError : No provider for Compiler

c# - 有什么方法可以将指纹生物识别设备连接到网站..?

typescript - 类型 'typeof Reflect 上不存在属性 'getMetadata'

html - 使位置固定不可滚动