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.

3
  • You have problem with AngularJS, or Angular2? Commented Mar 15, 2018 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. Commented Mar 15, 2018 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. Commented Mar 15, 2018 at 13:02

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

I already try this but facing custome1.js is not module. It would be great if you can give the detailed example.
in custome1.js you would bind your function to window.custome1, this would allow it to be accessible then

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.