引导图像轮播无法以角度

时间:2020-07-14 12:07:33

标签: javascript html angular twitter-bootstrap carousel

轮播的第一个图像出现在我的页面中,但是按钮不起作用,图像也没有移动。我尝试使用不同类型的引导轮播,但无济于事。我看到了一些建议将jQuery和Bootstrap链接添加到顶部的答案,所以我尝试了一下,但是也没有用。

home.component.html

<header>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    


    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        <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://placeimg.com/1080/500/animals" alt="First slide">
                <div class="carousel-caption d-none d-md-block">
                    <h5>My Caption Title (1st Image)</h5>
                    <p>The whole caption will only show up if the screen is at least medium size.</p>
                </div>
            </div>
            <div class="carousel-item">
                <img class="d-block w-100" src="https://placeimg.com/1080/500/arch" alt="Second slide">
            </div>
            <div class="carousel-item">
                <img class="d-block w-100" src="https://placeimg.com/1080/500/nature" 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>

</header>

index.html

<!doctype html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
  <meta charset="utf-8">
  <title>CastleApp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <app-root></app-root>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

Bootstrap需要使用JQuery进行此类操作。您需要在您的index.html中添加jquery或将其添加到<Person changed={this.nameChangedHandler.bind(this, value.id)} /> angular-cli.json(取决于您的Angular版本):

方法1(推荐):

首先运行以下命令以安装JQuery和Bootstrap:

angular.json

然后将这些行添加到$ npm install jquery bootstrap --save angular-cli.json(取决于您的Angular版本)

angular.json

方法2(不推荐):

在index.html中添加所需的脚本。不过请注意,因为每次您重新加载页面时都会下载这些模板。

"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.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"
  ],

来自documentation

的更多信息