Under 索引.html我已经声明了一个外部js文件,例如
<script data-siteid="XXXXXX" src="https://api.cartstack.com/js/customer-tracking/website.com_c7ee604471301b0bd028e8f19a535557.js" type="text/javascript">
</script>
我必须调用一个名为cartstack_updatecart()来自一个组件。 (该函数是从上面的链接生成的)。怎么做?
在您的组件中执行以下步骤:-
1) First add a reference of your external JS file for importing it to the component.
Import * as abcJS from '/YourExternalJS.js';
2) Now declare a "var" of the same name that your function has inside external JS.
declare var cartstack_updatecart: any;
3) ngOninit(){
cartstack_updatecart();
}
4) Do remember that your JQuery should be loaded first than your external JS file.
我在 ngoninitlifecycleHook 上调用了该函数。
另外,我宁愿建议您在脚本数组中的 angular-cli.json 文件中声明它,而不是在 Index.html 中声明外部 JS 文件。
一切顺利。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)