English 中文(简体)
如何利用ngx-virtual-scroller实现部件网的虚拟化
原标题:How to virtualize grid of components using ngx-virtual-scroller
  • 时间:2024-02-05 12:44:40
  •  标签:
  • angular

这里我有:https://stackblitz.com/edit/angular-56pper?file=src%2Findex.html

我想用电网的纳克-病毒-生物技术。

我创建了2个表格。 第一个表格应当实现虚拟化,但除非我设定固定的高度,否则就没有固定。 第二个表格并非虚拟化,而是我想要效仿的。 我想使用<条码>中要素的滚动条码,而不是表格内容,这就是为什么我需要将一些东西通过到<条码>。

我想知道这是否可行。 希望得到任何帮助。

问题回答

通常,如果我把母子确定为母子,做检查,确保母子从根元素中高身,那么,你的例子就是大事!

Also please note that material tabs destroys the content when its not the active tab, so I guess the height of the tab is not propagated for virtual scroll to do its thing!, we have the property preserveContent but that is only available for angular material latest version, where we can preserve the content of the tab without destroying it!

scroller html

    <div style="width: 100%; margin: 15px 10px; height:100%;" #test> <!--  changed here -->
      <virtual-scroller
        [enableUnequalChildrenSizes]="true"
        *ngIf="virtualize"
        #scroll
        [items]="data"
        [parentScroll]="test"
      > <!--  changed here -->
        <mat-card
          *ngFor="let i of scroll.viewPortItems"
          style="height: 150px; width: 200px;"
        >
          Item #{{ i }}
        </mat-card>
      </virtual-scroller>
      <div
        *ngIf="!virtualize"
        fxLayout="row wrap"
        fxLayoutAlign="start center"
        style="gap: 10px;"
      > <!--  changed here -->
        <mat-card *ngFor="let i of data" style="height: 150px; width: 200px;">
          Item #{{ i }}
        </mat-card>
      </div>
    </div>

main html

import { Component } from  @angular/core ;

@Component({
  selector:  my-app ,
  template: `
  <div fxFlex="100">
    <div fxLayout="row wrap"
         fxLayoutGap="10">
        <div *ngFor="let item of items; let i = index;"
             fxFlex="25" style="display:contents">
            <child-component>
            </child-component>
            <span *ngIf="items.length !== i + 1 && items.length!== 1">,&nbsp;</span>
            <span *ngIf="items.length === i + 1" style="
    flex-wrap: wrap;
    display: flex;
    flex: 1;"> this is a very long sssssss hhhh hhhhhhhhhhh hhh hhhhh hjjh  jhh
            </span>
        </div>
      </div>
</div>
  `,
  styleUrls: [ ./app.component.css ],
})
export class AppComponent {
  items = [1, 2, 3, 4, 5];
  name =  Angular ;
}

Stackblitz Demo





相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签