To load the files, locate the JavaScript files on your computer and place them inside the assets folder of the project.
To load the files, locate the JavaScript files on your computer and place them inside the assets folder of the project.
Next, open the angular.json file and locate the scripts property inside.
In here, place the path of each JavaScript file you want to load into the array.
"scripts": [
The assets folder is inside the src folder so we do “src/assets/” and the name of our file.
When we run our app, it will load and execute the code in JavaScript files.
Here is what is inside the ExampleJS1.js file:
Result:
Using Functions in the JS File
To use the functions or variables in the JavaScript files, declare a reference in a TypeScript file by typing declare and then the variable or function you want to reference.
Then call it in the code.
Using CDNs
If you have a CDN or a link to an online repository for the JavaScript file, you can just put script tags in the index.html page to load your files.
However, you cannot add script elements in the html page of your components.
To do load JavaScript files in a component, you have to do it manually inside the TypeScript file.