[英]Google tag manager with AngularJS - how to access variables declared in the head section of Index.html from Angular component
[英]How do you gain access to global variables and functions from Javascript scripts imported from index.html and use them in a component?
我正在使用 Angular 6,并且我有一个需要在项目中使用的私有 JavaScript 库。 我将它导入到 index.html 文件中。 该项目使用全局间隔函数。 如何在组件内部访问它们。 Angular 不会给我错误,也不会识别它们。
index.html
.....
<script src="https://somefile.js type="text/javascript" charset="utf-8">
.....
// has a function
doXYZ() in the global namespace
somecomponent.ts
......
ngOnInit() {
doXYZ() //try to call globally imported function
}
......
错误:使用
ng serve
时找不到名称 doXYZ
您也许能够访问window
对象上的全局命名空间。
尝试像这样访问您想要的功能:
window['doXYZ']();
window
是全局可访问的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.