Include external js file in angular 5.0.0 project

I am trying to include hello.js in my angular 5.0.2 project.

Below is the cli version

enter image description here

I added the script file to the angular-cli.json file.

"scripts": [
        "./js/hello.js",
        "./js/hello.polyfill.js",
       ]

The path is correct since I am also loading the style in angular-cli.json, which loads fine.

In my service file, I import hi, as shown below:

declare var hello: any;
declare var gapi: any;

but when I run ng build, the console will show an error:

Cannot find module 'hello'.

If I upload files through the script tag in index.html, the code and import work fine. Only when I add it to the angular-cli.json file does it stop working.

Please guide thanks

+4
source share
1 answer

You must also specify a folder with resources:

"scripts": [
        "./assets/js/hello.js",
        "./assets/js/hello.polyfill.js",
       ]
+1

Source: https://habr.com/ru/post/1689766/


All Articles