Fireship · @fireship
Angular 7 Virtual Scroll - To Infinity and Beyond
Uploaded October 22, 2018 · Length 11:44
Summary
Learn how to implement virtual scrolling in Angular 7 with the component development kit (CDK) for high-performance lists and infinite scrolling.
- angular virtual scroll
- angular 7 cdk
- infinite scrolling
- high-performance lists
- angular component development kit
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
angular seven is officially here and one
- 0:09
of its coolest new features is the
- 0:10
virtual scroll behavior in the component
- 0:12
development kit it allows you to easily
- 0:14
build a high-performance list that only
- 0:16
renders the items visible to the user in
- 0:18
today's video I'll show you everything
- 0:20
you need to know about virtual scroll
- 0:21
but we'll also take things a few steps
- 0:23
further by making an animated infinite
- 0:25
and real-time if you're new here like
- 0:27
and subscribe and I'm giving away some
- 0:29
winter swag with this video all you have
- 0:31
to do is leave a comment below and we'll
- 0:32
pick a winner on the live stream on
- 0:34
Wednesday so first of all what is
- 0:36
virtual scrolling and why would you want
- 0:38
to use it it's useful when you have a
- 0:40
large list of items to loop over but you
- 0:42
only want to render the items that are
- 0:44
visible in the viewport this should give
- 0:45
you much smoother performance when
- 0:47
working with big lists because the
- 0:48
browser only needs to render a small
- 0:50
subset of the data the cdk provides a
- 0:53
handful of components and directives to
- 0:55
make virtual scrolling super easy in
- 0:57
addition it provides a handful of tools
- 0:58
that makes it much easier to measure the
- 1:00
scrolled element which we can then use
- 1:02
to pull data from our back-end database
- 1:03
in batches giving us an infinite
- 1:05
real-time virtual scroll the first thing
- 1:08
you want to do is make sure you're
- 1:09
up-to-date with angular version 7 then
- 1:12
we can quickly add the cdk to our app by
- 1:14
running ng add angular material you'll
- 1:16
notice that when you do this in angular
- 1:18
7 it gives you a prompt to have
- 1:19
questions to go through you can just
- 1:21
select the defaults and then if you also
- 1:23
want to follow along with the firebase
- 1:24
part you'll want to install angular fire
- 1:26
at this point as well but I'm going to
- 1:28
start with just the cdk basics before we
- 1:30
get to that point if we jump over to my
- 1:33
app module you can see that I'm
- 1:34
importing the scrolling module from the
- 1:36
cdk and then I also have a couple of
- 1:38
components generated just for this demo
- 1:40
so you want to make sure that you have
- 1:41
the scrolling module here in the import
- 1:43
section and then optionally angularfire
- 1:45
for the back-end stuff now that we're
- 1:47
all set up let's start by looking at the
- 1:49
basics of virtual scroll the first thing
- 1:51
you'll need is a big list of something
- 1:53
to loop over so I want to show you how
- 1:54
to generate a ton of fake data really
- 1:56
quickly first I wrote my own helper
- 1:58
function that will return a random emoji


