Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular cdk 虚拟滚动例子 #115

Open
deepthan opened this issue Nov 26, 2020 · 0 comments
Open

Angular cdk 虚拟滚动例子 #115

deepthan opened this issue Nov 26, 2020 · 0 comments

Comments

@deepthan
Copy link
Owner

Angular cdk 虚拟滚动例子

module

import { ScrollDispatchModule } from '@angular/cdk/scrolling';

@NgModule({
  imports: [
    ScrollDispatchModule,
  ],
})

component.ts

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';

@Component({
  selector: 'vir-ckd-demo',
  templateUrl: './ckd-demo.component.html',
  styleUrls: ['./ckd-demo.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CkdDemoComponent implements OnInit {
  items = Array.from({ length: 100000 }).map((_, i) => `第${i}个`);
  constructor() {}

  ngOnInit() {}
}

component.html

<cdk-virtual-scroll-viewport itemSize="10" class="example-viewport">
  <div *cdkVirtualFor="let item of items" class="example-item">{{ item }}</div>
</cdk-virtual-scroll-viewport>

==itemSize==注意它的作用

component.css

.example-viewport {
  height: 200px;
  width: 200px;
  border: 1px solid black;
}

.example-item {
  height: 50px;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant