找不到脚本index.html angular 2

时间:2017-06-30 06:08:46

标签: javascript html angular

我有我的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脚本。当我像这样(注释行)包含它时,它不起作用。帮我解决这个问题,因为我需要包含一些其他脚本。 “不起作用”是指在浏览器的控制台中找不到注释脚本的所有时间。

3 个答案:

答案 0 :(得分:2)

确保您提供“jquery-1.6.4.js”的路径。检查src / scripts。 如果它在那里你应该包括它有点像这样, “〜/ src目录/脚本/ jQuery的1.6.4.js”。 假设你有“src”文件夹,其中存在“script”文件夹,其中包含你的jquery文件。

答案 1 :(得分:1)

尝试在根项目中向angular-cli.json添加脚本和样式,如下所示:

"apps": [{
    ...
    ... 
    "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "./styles.css"
    ],
    "scripts": [
        "assets/js/jquery.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js",
        "assets/js/custom.js"
    ],

答案 2 :(得分:0)

最新版本的angular-cli(angular-cli:1.0.0-beta.19-3)在src目录下提供了一个assets文件夹。您只需要添加图像标记的src属性,如下所示,

   <img src="./assets/logo.png">

但事实证明,我不需要在index.html中包含任何脚本。主要问题是有时我的项目没有检测到变化。我的意思是 - 在过去我添加了一行,在index.html上包含jquery,我的项目没有检测到它,因此浏览器没有显示任何错误(未找到),之后我一直在那个我正在使用jquery,因为其中包括index.html上的jquery。但实际上jquery正在工作,因为我也以不同的方式包含它。所以要小心。