簡體   English   中英

將外部js文件包含到angular 5.0.0項目中

[英]Include External js file to angular 5.0.0 project

我試圖在我的角度5.0.2項目中包含hello.js

以下是cli版本

在此輸入圖像描述

我已將腳本文件添加到angular-cli.json文件中。

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

路徑是正確的,因為我也在angular-cli.json中加載樣式,它們正在加載正常。

在我的服務文件中,我導入hello如下:

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

但是當我運行ng build時,控制台顯示錯誤:

找不到模塊'hello'。

如果我通過index.html中的腳本標記加載文件,代碼和導入工作正常。只有當我將它添加到angular-cli.json文件時,它才會停止工作。

請指導謝謝

在angular-cli.json或angular.json中編輯腳本數組。

您還必須指定assets文件夾:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM