繁体   English   中英

找不到脚本index.html angular 2

[英]Script not found index.html angular 2

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

确保提供“ jquery-1.6.4.js”的路径,该路径恰好位于该位置。 检查src /脚本。 如果存在,则应将其添加为“〜/ src / scripts / jquery-1.6.4.js”。 假设您有“ src”文件夹,其中存在“ script”文件夹,其中包含您的jquery文件。

尝试将脚本和样式添加到根项目中的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"
    ],

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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