Cdk virtual-scroll inside mat-select for mat-option

后端 未结 2 1125
臣服心动
臣服心动 2021-02-14 20:35

Has anyone been able to use virtual-scroll inside mat-select as shown below ?


    
        

        
2条回答
  •  后悔当初
    2021-02-14 21:16

    I think i have solved this:

    https://stackblitz.com/edit/angular-gs4scp

    The key things are when the mat select opens panel we trigger cdkVirtualScrollViewPort scroll and check view port size.

      openChange($event: boolean) {
        console.log("open change", $event);
        if ($event) {
          this.cdkVirtualScrollViewPort.scrollToIndex(0);
          this.cdkVirtualScrollViewPort.checkViewportSize();
        } else {
        }
      }
    

    Where we get the reference to the virtual scroll viewport using @ViewChild

    @ViewChild(CdkVirtualScrollViewport, { static: false })
      cdkVirtualScrollViewPort: CdkVirtualScrollViewport;
    

    Other relevant pieces in the template are are pretty simple:-

    
        
        
          {{ itemTrigger }}
        
            
                {{item}}
            
        
        Justa hint
    
    

提交回复
热议问题