Fireship · @fireship
Draggable Sortable Firestore
Uploaded October 8, 2018 · Length 7:57
Summary
Build a sortable list with drag-and-drop functionality using Firestore and Angular, persisting data in a back-end database.
- angular firestore
- drag and drop sortable list
- firebase database
- angular directives
- shopify draggable library
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
one of the more challenging features to
- 0:08
build on a web application is a
- 0:10
drag-and-drop sortable list and it's
- 0:12
even more challenging if you need to
- 0:13
persist the data in a back-end database
- 0:15
instead of trying to reinvent the wheel
- 0:17
we're going to use a library called
- 0:19
draggable that's maintained by shop live
- 0:21
it's relatively lightweight and we can
- 0:23
wrap it in angular to make drag and drop
- 0:24
features much more enjoyable to code if
- 0:26
you're new the channel like and
- 0:28
subscribe and you can find the source
- 0:29
code on angular firebase comm what we're
- 0:32
building today is a sortable list of
- 0:33
emojis the user can add or remove items
- 0:36
from the list and they can drag items to
- 0:38
change the order and have that order be
- 0:40
saved in the database this is a pretty
- 0:42
complex thing to do from scratch because
- 0:44
if you notice when we drag an item it
- 0:45
creates a mirror of the original element
- 0:47
and toggles a whole bunch of CSS classes
- 0:49
on the container and the individual
- 0:51
items themselves draggable will make
- 0:53
this feature surprisingly easy but also
- 0:56
give us enough flexibility to build
- 0:57
something unique in addition firestore
- 0:59
recently released a couple of new helper
- 1:01
methods that make it easy to add or
- 1:03
remove elements from an array so we'll
- 1:05
take a look at those as well but the
- 1:07
first thing you need to get started is
- 1:08
an angular app with angular fire
- 1:10
installed from there we'll go to the
- 1:12
command line and install draggable with
- 1:13
NPM there are two main elements to this
- 1:17
demo first we have a smart component
- 1:19
which is our emoji component and it
- 1:21
handles retrieving items from the
- 1:22
database and can also add or remove new
- 1:24
emojis to the list then we have a
- 1:26
directive called sortable which I'm
- 1:28
going to call our dumb component because
- 1:30
a directive is essentially just a
- 1:31
component that doesn't have a custom
- 1:33
HTML template it can do pretty much
- 1:35
everything a component can do but
- 1:37
instead it attaches itself to a host
- 1:39
element and extends the functionality of
- 1:41
that element when working with sort of a
- 1:43
list like this you'll usually attach
- 1:44
this to an unordered list and then have
- 1:46
your list items be sortable within it
- 1:49
we'll start by building out the
- 1:50
directive and you'll notice that we're
- 1:52
importing a bunch of things here from
- 1:53
angular core and this is also where
- 1:56
we'll import sortable from Shopify
- 1:58
draggable we're going to implement the


