Fireship · @fireship
Simple Pagination with Firebase and Angular 4
Uploaded June 30, 2017 · Length 4:20
Summary
build simple pagination with firebase and angular fire, navigating through comments with next and previous buttons
- firebase pagination
- angular fire
- pagination in angular
- firebase comments
- angular pagination
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
and this episode we're going to build a
- 0:02
simple pagination feature using firebase
- 0:05
and angular fire to package this
- 0:08
solution allows the user to click a next
- 0:10
or previous button to navigate through a
- 0:13
firebase to list observable the benefit
- 0:16
of this approach is that it can be
- 0:17
applied to a data set of any size but
- 0:20
the drawback is that it's impossible to
- 0:22
really implement page numbers for
- 0:24
pagination in the database we have a
- 0:26
series of common nested under their
- 0:29
associated post ID let's start by
- 0:33
retrieving a firebase list observable
- 0:35
from the service first we import the
- 0:37
angular fired database and then we build
- 0:40
a function that will take a ghost ID an
- 0:44
offset which is the number of comments
- 0:46
we want to retrieve and a start key
- 0:48
which is where we'll start the actual
- 0:50
query in firebase we can't use a numeric
- 0:54
offset like you would in a sequel
- 0:55
database so we keep track of the key and
- 0:58
use that as the offset point for each
- 1:00
query the key for the next page is
- 1:03
determined by grabbing one extra comment
- 1:05
from the database and we use that
- 1:07
comments key is the offset point for the
- 1:09
following page
- 1:11
[Music]
- 1:15
now we can start building the component
- 1:17
in the template we're going to loop
- 1:20
through a list of comments but notice
- 1:22
we're not using the async pipe because
- 1:24
we're actually going to unwrap the
- 1:26
observable in the component type script
- 1:28
we also had a couple buttons just for
- 1:31
navigating between the next and previous
- 1:33
pages we also want to disable these
- 1:36
buttons if there isn't a next or
- 1:39
previous page to navigate to in the type
- 1:44
script we start by injecting the
- 1:46
comments service and we also import
- 1:48
lodash which we'll be using to do a lot
- 1:50
of the array operations in this
- 1:52
implementation the comments variable
- 1:55
will hold the actual comments from the
- 1:57
observable the offset will be the number


