如何在 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/