简体   繁体   中英

Include External js file to angular 5.0.0 project

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

Below is the cli version

在此输入图像描述

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

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

The path is correct as i'm also loading style in the angular-cli.json which are loading fine.

In my service file i'm importing hello as below:

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

but when i run ng build the console shows the error:

Cannot find module 'hello'.

If i load the files through script tag in the index.html the code and imports works fine .Only when i add it to the angular-cli.json file it stops working.

Please guide Thanks

Edit the scripts array in angular-cli.json or angular.json.

You must also specify the assets folder:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM