简体   繁体   English

如何显示和限制 ng zorro 卡阵列为 3,它将以角度添加分页

[英]How to display and limit the ng zorro card array to 3 and it will add pagination in angular

how to limit the display of ng zorro card to per 3 card and it will add a pagination.如何将ng zorro卡的显示限制为每3张卡,它将添加分页。

here's the code: home.component.html这是代码: home.component.html

<ng-container *ngFor="let data of data">
    <nz-card style="width:300px;" [nzActions]="[actionSetting,actionEdit,actionEllipsis]">
        <nz-card-meta nzTitle="{{data.title}}" nzDescription="{{data.description}}" [nzAvatar]="avatarTemplate"></nz-card-meta>
    </nz-card>
    <ng-template #actionSetting>
    <div class="action-wrapper">
      <i nz-icon type="setting"></i>{{idx}}
    </div>
  </ng-template>
  <ng-template #actionEdit>
    <div class="action-wrapper">
      <i nz-icon type="edit"></i>{{idx}}
    </div>
  </ng-template>
  <ng-template #actionEllipsis>
    <div class="action-wrapper">
      <i nz-icon type="ellipsis"></i>{{idx}}
    </div>
  </ng-template>
</ng-container>

home.component.ts home.component.ts

  data = [
    { title: 'title1', description: 'description1' },
    { title: 'title2', description: 'description2' },
    { title: 'title3', description: 'description3' },
    { title: 'title4', description: 'description4' },
    { title: 'title5', description: 'description5' },
    { title: 'title6', description: 'description6' },
    { title: 'title7', description: 'description7' },
    { title: 'title8', description: 'description8' },
    { title: 'title9', description: 'description9' },
    { title: 'title10', description: 'description10' }
  ]

what I want to do is to limit it item to 3 card and it will add pagination.我想要做的是将它的项目限制为 3 张卡片,它会添加分页。

if the array is more than 3 records it will add the pagination, if just 3 the pagination will not display.如果数组超过 3 条记录,它将添加分页,如果只有 3 条记录,则不会显示分页。

you should limit the ngFor iteration and then use ngIf for the pagination:您应该限制 ngFor 迭代,然后使用 ngIf 进行分页:

 <ng-contaier *ngFor="let item of data | slice:initValue:endValue">
    ....
 </ng-container>

 <div *ngIf="data.length > 3">
     <!-- pagination code  define initValue and endValue here depending on your pagination!! -->
 </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM