簡體   English   中英

Angular:添加額外的js時出現未捕獲的SyntaxError

[英]Angular: Uncaught SyntaxError when adding extra js

添加: 將本地@ angular / cli從1.6.1降級到1.5.5后,不會發生此錯誤。

我的Angular / src /目錄中的main.js文件:

$(document).ready(function() {
    alert('test'); //or any other js code   
});

在.angular-cli.json中添加:

"scripts": [
  "main.js"
],

jQuery CDN添加在index.html中。

有了所有這些,腳本就無法正常工作,我可以在控制台中找到它:

scripts.bundle.js:1 Uncaught SyntaxError: Unexpected token {

這是我從錯誤源中得到的內容: 在此處輸入圖片說明

Angular版本是5.1.1。

僅當您將腳本命名為main.js時,才會發生這種情況。 任何其他名稱都可以正常工作。

暫無
暫無

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

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