Call a function of external js file in angular 5 component

后端 未结 1 1386
星月不相逢
星月不相逢 2021-01-15 01:28

Under index.html I have delcared an external js file like

相关标签:
1条回答
  • 2021-01-15 02:08

    Follow below steps in your component:-

    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.
    

    I have called that function on ngoninit lifecycleHook. Also instead of declaring external JS file inside Index.html, I would rather suggest you to declare it in angular-cli.json file in scripts array. All the best.

    0 讨论(0)
提交回复
热议问题