脚本不会从.angular-cli.json加载 [英] Scripts don't load from .angular-cli.json

查看:57
本文介绍了脚本不会从.angular-cli.json加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向.angular-cli.json文件中添加了新的脚本,如下所示:

I added new scripts to my .angular-cli.json file like this:

    "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/popper.js/dist/popper.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ]

然后我将引导程序中的轮播添加到我的app.component.html文件中(仅从文档中复制):

Then I added carousel from bootstrap to my app.component.html file like that (just copy from documentation):

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" style="background: #000000;">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="https://ocdn.eu/pulscms-transforms/1/jQxktkpTURBXy83MjQ2M2M3NjAzZmU5MTA0MTZjOWJiYzVlY2U0NzUzNy5wbmeRkwLNAyYA" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://ocdn.eu/pulscms-transforms/1/jQxktkpTURBXy83MjQ2M2M3NjAzZmU5MTA0MTZjOWJiYzVlY2U0NzUzNy5wbmeRkwLNAyYA" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://ocdn.eu/pulscms-transforms/1/jQxktkpTURBXy83MjQ2M2M3NjAzZmU5MTA0MTZjOWJiYzVlY2U0NzUzNy5wbmeRkwLNAyYA" alt="Third slide">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

当我尝试像这样从我的index.html文件中加载脚本时(一切正常):

When I try load scripts from my index.html file like that (everything works):

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

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

</head>
<body>
  <app-root></app-root>
</body>
</html>

有什么解决办法吗?我逐个建立,重新发球,但没有帮助.

Is there any solution? I make build by ng build, restar ng serve and it didn't help.

推荐答案

我在 angular-cli 应用中遇到了类似的问题.我终于发现我的index.html缺少一个包含项:

I had a similar issue with an angular-cli app. I finally discovered that my index.html was missing an include:

<script type="text/javascript" src="scripts.bundle.js">

添加该脚本后,它会为我修复.

Adding that script include fixed it for me.

仅供参考,我的服务器设置未使用生成的index.html ...我可能复制并粘贴了index.html脚本包含的内容,然后添加了脚本部分,稍后导致问题.

FYI my server setup doesn't use the generated index.html ... I probably copied and pasted the index.html script includes and then added the scripts section later leading to the issue.

这篇关于脚本不会从.angular-cli.json加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆