Html 当长度达到4时,显示新容器div中的数据
当长度达到4时,我需要一些帮助来在新的容器div中显示我的ngFor数据。在多个div中硬编码数据更容易,但使用ngFor在单个容器div中显示数据 下面的代码假定在图书节网格DIV中有四个图书节子网格DIV 我的尝试Html 当长度达到4时,显示新容器div中的数据,html,angular,Html,Angular,当长度达到4时,我需要一些帮助来在新的容器div中显示我的ngFor数据。在多个div中硬编码数据更容易,但使用ngFor在单个容器div中显示数据 下面的代码假定在图书节网格DIV中有四个图书节子网格DIV 我的尝试 <div class="book-section-grid"> <div *ngFor="let book of books" class="book-section-subGrid"> <img src="assets/imag
<div class="book-section-grid">
<div *ngFor="let book of books" class="book-section-subGrid">
<img src="assets/images/book1-1.png" alt="">
<h4>{{book?.title}}</h4>
<span>by <a href="#">Michael Freeman</a></span>
</div>
</div>
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
摄影师的问题解决者
通过
像这样试试
<div class="book-section-grid">
<div *ngFor="let book of books; let index = index;" class="book-section-subGrid">
<div *ngIf="index < 5; else elseBlock">
<h4>{{book?.title}}</h4>
<img height="100" width="100" src="https://images.pexels.com/photos/1226302/pexels-photo-1226302.jpeg" alt="">
<span>by <a href="#">Michael Freeman</a></span>
</div>
<ng-template #elseBlock>
<h1>{{book?.title}}</h1>
<img height="50" width="50"src="https://images.pexels.com/photos/1226302/pexels-photo-1226302.jpeg" alt="">
<span>by <a href="#">Michael Freeman</a></span>
</ng-template>
</div>
</div>
{{书?.title}
通过
{{书?.title}
通过
我想你可以利用角度
您可以找到一个示例实现。您到底在寻找什么?为什么不使用“book”索引?然后你可以*ngIf当它等于\大于4时,请多加几盏灯,你到底需要什么,只需使用
https://angular.io/api/common/NgSwitch
。这是stackblitz的工作。谢谢,我们已经接近解决方案了。请查看我编辑的问题,以便更好地理解,谢谢。我的问题刚刚编辑,以便更好地解释,请审阅。谢谢