我正在尝试使用bootstrap 4轮播作为角度5的内容滑块。
我想做一个* ngFor和活动轮播项目,显示4 * ngFor结果。
这是我到目前为止。
<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" role="listbox">
<div class="carousel-item active">
<div class="row mar-30">
<div class=" col-md-3"
*ngFor="let blog of blogs | async; let i = index"
>
<div *ngIf="i<4">
<app-blogcard
(checked)="OnChecked($event)"
[blog]="blog"
></app-blogcard>
</div>
</div>
</div>
</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>
这将显示活动轮播项目的四个项目,因为我的* ngIf限制为4.无论如何,我可以更好地做到这一点,而不必在下一个轮播项目上做另外的* ngFor?
答案 0 :(得分:0)
在slice
*ngFor
<div class=" col-md-3"
*ngFor="let blog of (blogs ? blogs.slice(0,4): []) | async; let i = index"
>
<div >
<app-blogcard
(checked)="OnChecked($event)"
[blog]="blog"
></app-blogcard>
</div>
答案 1 :(得分:0)
我没有完全解决你的问题,但我“完善了”你的代码。随意看看:
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<ng-container *ngFor="let blog of blogs?.slice(0, 4) | async; let i = index">
<li data-target="#carouselExampleIndicators" data-slide-to="{{i}}"></li>
</ng-container>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<div class="row mar-30">
<div class=" col-md-3" *ngFor="let blog of blogs?.slice(0, 4)">
<app-blogcard (checked)="OnChecked($event)" [blog]="blog"></app-blogcard>
</div>
</div>
</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>