Bootstrap Carousel中的幻灯片不是水平放置的,幻灯片仅是垂直放置的

时间:2018-09-13 05:52:18

标签: angular carousel

当前行为 Bootstrap Carousel中的幻灯片不来了,幻灯片仅在垂直方向上来了。在轮播中,我们希望幻灯片只能水平放置,我还附加了当前的行为截图。

enter image description here

预期的行为 轮播中的幻灯片应像下面的示例屏幕截图一样水平放置 (示例链接https://ng-bootstrap.github.io/#/components/carousel/examples

enter image description here 通过说明将问题最小化 从github链接https://github.com/gg-gg-v1/v1_ComponentsWithSEO下载代码后 运行npm install 运行服务 将在浏览器中启动

示例存储库 https://github.com/gg-gg-v1/v1_ComponentsWithSEO

环境 Angular CLI:6.2.1 节点:8.11.3 操作系统:win32 x64 角度:6.1.7 ...动画,通用,编译器,compiler-cli,核心,形式 ... http,语言服务,平台浏览器 ...平台浏览器动态,平台服务器,路由器

slider.component.ts

import { Component, OnInit } from '@angular/core';
import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-slider',
  templateUrl: './slider.component.html',
  styleUrls: ['./slider.component.css'],
  providers: [NgbCarouselConfig]  // add NgbCarouselConfig to the component providers
})
export class SliderComponent implements OnInit {
  images = [1, 2, 3, 4].map(() => `https://picsum.photos/900/500?random&t=${Math.random()}`);

  constructor(config: NgbCarouselConfig) {
    // customize default values of carousels used by this component tree
    config.interval = 10000;
    config.wrap = false;
    config.keyboard = false;
    config.pauseOnHover = false;
  }
  ngOnInit() {
      }
}

slider.component.html

  <ngb-carousel *ngIf="images">
      <ng-template ngbSlide>
        <img [src]="images[0]" alt="Random first slide">
        <div class="carousel-caption">
          <h3>10 seconds between slides...</h3>
          <p>This carousel uses customized default values.</p>
        </div>
      </ng-template>
      <ng-template ngbSlide>
        <img [src]="images[1]" alt="Random second slide">
        <div class="carousel-caption">
          <h3>No mouse events...</h3>
          <p>This carousel doesn't pause or resume on mouse events</p>
        </div>
      </ng-template>
      <ng-template ngbSlide>
        <img [src]="images[2]"  alt="Random third slide">
        <div class="carousel-caption">
          <h3>No keyboard...</h3>
          <p>This carousel uses customized default values.</p>
        </div>
      </ng-template>
      <ng-template ngbSlide>
        <img [src]="images[3]" alt="Random fourth slide">
        <div class="carousel-caption">
          <h3>And no wrap after last slide.</h3>
          <p>This carousel uses customized default values.</p>
        </div>
      </ng-template>
    </ngb-carousel>

2 个答案:

答案 0 :(得分:0)

您尚未导入bootstrap.css。将其导入angular.json样式数组或index.html中可直接为它提供cdn引用:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />

答案 1 :(得分:0)

您需要安装引导程序:npm install bootstrap @ 4 将其链接(通过index.html),相同的代码将起作用

这也记录在https://github.com/ng-bootstrap/ng-bootstrap/issues/2141