javascript - 轮播问题 | 角 6
问题描述
我正在使用 Angular 6,并且我有 topAdvertisementList[] 正在返回 2 条记录以显示在我的轮播中,并显示一个固定的图像,但我看到轮播中只显示了一条记录!,我认为我的 HTML 脚本有问题.
你能帮忙吗?
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li *ngFor="let add of topAdvertisementList; let i=index"
data-target="#carousel-example-generic" data-slide-to="i" class="active"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div *ngFor="let add of topAdvertisementList; let i=index" [ngClass]="{
'carousel-item active':i === 0,
'carousel-item':i > 0 }">
<img src="assets/modules/dummy-assets/common/img/photos/1.jpeg" alt="{{i}}">
</div>
</div>
<a class="carousel-control-prev" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
解决方案
格式不是问题,正确的脚本是
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li *ngFor="let add of topAdvertisementList; index as i" data-target="#carousel-example-generic" data-slide-to="i" class="active"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div *ngFor="let add of topAdvertisementList; index as i" [ngClass]="{
'carousel-item active':i == 0,
'carousel-item':i >= 0}">
<img *ngIf="add.adv_file" src="{{genericService.baseUrl}}/{{add.adv_file}}" alt="Advertisement">
<img *ngIf="!add.adv_file" src="assets/images/no-image.jpg" alt="Advertisement">
</div>
</div>
<a class="carousel-control-prev" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
推荐阅读
- python - 从字典的键和值中删除字符?
- neo4j - 在 Neo4j 中为每个组生成 UUID
- github-pages - GitHub Pages:无法访问此站点
- python - 实时 subprocess.popen 输出(尝试了我能找到的一切)
- codeigniter-3 - 在我的 codeigniter 项目中用户登录期间出现错误
- python - 在python中以通用形式尝试和除外
- jenkins-pipeline - 为什么詹金斯不会用变量迭代
- typescript - TypeScript 循环槽对象
- python - 我通过 open cv2 不断收到此错误进行人脸检测
- c++ - VIDIOC_QBUF:设备或资源繁忙 V4L2 MEMORY USERPTR