-2

I have already mention my js file path in angular.cli, it was loading only one time when angular app was initilizing and when we get back to the component then it was not loading so please give me some suggestion over this.

Thanks for your help in advance.:)

gaurav
  • 3
  • 1
  • Please share the code about things you have tried. Can you share the code snippets? – Sachin G. Apr 26 '18 at 05:28
  • Do you want to load "some" same js two times? – Sachin G. Apr 26 '18 at 05:30
  • when you mention in angular cli json it load file at once and it will be avilable to all you component , what is you point here its not loading 2 time – Pranay Rana Apr 26 '18 at 05:33
  • public loadScript(url) { let node = document.createElement('script'); node.src = url; node.type = 'text/javascript'; node.async = true; node.charset = 'utf-8'; document.getElementsByTagName('head')[0].appendChild(node); console.log(node); } – gaurav Apr 26 '18 at 05:33
  • This can help you to load js files at component level https://stackoverflow.com/a/44276683/6048399 – Harish98 Apr 26 '18 at 05:42

1 Answers1

1

This imay help for you.

Please try to mention it on Index.html. or load script dynamatically on component.

function loadJS(file) {
    // DOM: Create the script element
    var jsElm = document.createElement("script");
    // set the type attribute
    jsElm.type = "application/javascript";
    // make the script element load file
    jsElm.src = file;
    // finally insert the element to the body element in order to load the script
    document.body.appendChild(jsElm);
}
Kunvar Singh
  • 1,779
  • 2
  • 13
  • 21