Angular 使用带有 *ngfor 的轮播

发布于 2025-01-10 04:57:37 字数 1313 浏览 3 评论 0原文

我正在尝试制作一个旋转木马。 该轮播图像从字符串数组中获取其图像路径字符串。 当我单击向左或向右箭头时,我希望它增加或减少索引,这样我就可以更改显示的图像。 我怎样才能做到这一点。 不允许使用 ts 代码,只能使用 html。

 <div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
      <div class="carousel-inner">               
        <ul  *ngFor="let carImagePath of carImagePaths; let i= index;first as isFirst">
          <div [ngClass]="isFirst ? 'carousel-item active' : 'carousel-item' "> 
            <li><img [src]="imageUrl+carImagePath" class="d-block w-100" alt="..."></li> 
          </div>
        </ul> 
        </div>
          <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
          </button>
          <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
          </button>
      </div>
 </div>

I am trying to make a carousel.
This carousel image gets its imagepath string from a string array.
when i click left or right arrow I want it to increase or decrease index, so i can change image which is shown.
how can i mak this happen.
NO ts code allowed, only html can be used.

 <div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
      <div class="carousel-inner">               
        <ul  *ngFor="let carImagePath of carImagePaths; let i= index;first as isFirst">
          <div [ngClass]="isFirst ? 'carousel-item active' : 'carousel-item' "> 
            <li><img [src]="imageUrl+carImagePath" class="d-block w-100" alt="..."></li> 
          </div>
        </ul> 
        </div>
          <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
          </button>
          <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
          </button>
      </div>
 </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2025-01-17 04:57:37

作为解决方案,我放弃了尝试使用普通的引导轮播。我尝试了角度引导轮播。 ng 添加 ngx-bootstrap --component 轮播。将其安装到终端。并通过这个网站使用它自己的html:
https://valor-software.com/ngx-bootstrap/ #/components/carousel?tab=overview

现在它可以工作了。

As a solution i gave up trying to use normal bootstrap carousel. I tried angular bootstrap carousel. ng add ngx-bootstrap --component carousel . intallled this to terminal. and used it own html from via this site:
https://valor-software.com/ngx-bootstrap/#/components/carousel?tab=overview

Now it is working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文