0

I have custom1.js, custom2.js, custom3.js JS files and load these files into Angular component1,component2,component3 respectively. I can add these files to the index.html files but Don't want to load these files globally.

Need to load these files component specific. Also, I went throw this Stackoverflow answer but not getting exactly way to solve this problem. Is there any other ways to solve this problem.?

Thank in advance.

ranjit redekar
  • 919
  • 1
  • 12
  • 24
  • You have problem with AngularJS, or Angular2? – Krzysztof Raciniewski Mar 15 '18 at 12:10
  • @KrzysztofRaciniewski As per my knowledge Angular means Angular 2,4,5 which works with Typescript as well as Javascript and AngularJS means AngularJS (v1) which works with only Javascript. Still, I update the question. – ranjit redekar Mar 15 '18 at 12:17
  • This would depend on what the contents of your custom.js file is. Loading a file, even in a component would load it globaly if you don't take the correct precautions. – Mathieu de Lorimier Mar 15 '18 at 13:02

1 Answers1

3

You will need to add the js files to your angular-cli.json and then import them into each component as needed at the top of the component.ts file as follows

declare const custom1: any
Shane
  • 659
  • 1
  • 9
  • 19
  • I already try this but facing custome1.js is not module. It would be great if you can give the detailed example. – ranjit redekar Mar 15 '18 at 12:33
  • in custome1.js you would bind your function to window.custome1, this would allow it to be accessible then – Shane Mar 15 '18 at 12:37