2017-06-29 20 views
-1

我有我的index.html:不能包含腳本angular2的index.html(未找到)

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Aerosmith Messenger</title> 
    <base href="/"> 

    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" 
rel="stylesheet" /> 
    <link rel="icon" type="image/x-icon" href="favicon.ico" /> 
    <link rel="stylesheet" href="assets/spinner.css" /> 

    <!--<script src="src/scripts/jquery-1.6.4.js"></script>--> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.js"> 

</script> 
</head> 
<body> 
    <am-root> 
    <div class="spinner"> 
     <div class="double-bounce1"></div> 
     <div class="double-bounce2"></div> 
    </div> 
    </am-root> 
</body> 
</html> 

我想包括jQuery腳本。當我像這樣包含它時它不起作用(註釋行)。幫我解決這個問題,因爲我需要包含一些其他腳本。 「不工作」我的意思是,在瀏覽器的控制檯中找不到所有評論腳本。

+1

「不工作」是沒有問題的技術說明。你看過瀏覽器的開發工具嗎? – Rob

+0

如果這是你的根html文件,你似乎缺少一些關於angular的核心知識。 –

+0

「不工作」我的意思是在瀏覽器的控制檯中找不到所有評論腳本。 –

回答

1
npm install --save jquery 
npm install -D @types/jquery 

在你app.module.ts文件:

import $ from 'jquery'; 

// Works : 
$('#foo').value(); 
+0

最新版本的angular-cli(angular-cli:1.0.0-beta.19-3)在src目錄下提供了一個assets文件夾。你只需要像這樣添加一個圖像標籤的src屬性:

1

沒有什麼錯,你把它的方式。也許你是從worng路徑調用它,或者js文件不是一個好的預構建。轉到瀏覽器並檢查它是否能找到js文件。

+0

最新版本的angular-cli(angular-cli:1.0.0-beta.19-3)在src目錄下提供了assets文件夾。你只需要像這樣添加一個圖像標籤的src屬性:

1

確保您的jQuery JavaScript文件位於您的項目在src/scripts/

+0

最新版本的angular-cli(angular-cli:1.0.0-beta.19-3)在src目錄下提供了assets文件夾。你只需要像這樣添加圖片標籤的src屬性: