Fireship · @fireship
Autocomplete Search with Angular4 and Firebase
Uploaded June 22, 2017 · Length 4:36
Summary
build autocomplete search with angular4 and firebase, real-time database, and rxjs
- angular4
- firebase
- autocomplete
- real-time database
- rxjs
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
in this episode we're going to build an
- 0:02
autocomplete feature using angular for
- 0:04
and firebase users will be able to type
- 0:07
into a search field and the results will
- 0:09
automatically be updated in the fields
- 0:11
below in order to demonstrate this
- 0:15
feature we have the real-time database
- 0:17
populated with a series of movies the
- 0:20
search function will match string
- 0:22
patterns to the title on a database
- 0:24
similar to the sequel like operator
- 0:27
let's get the app started by building
- 0:30
the service the service is very simple
- 0:36
all we needed to do is return a firebase
- 0:39
list observable that we can ask a query
- 0:42
to and this query can take either just a
- 0:46
regular string object or it can take a
- 0:48
subject from rxjs passing to the subject
- 0:56
allows you to call next on the underline
- 0:58
subject which is a lot easier more
- 1:00
intuitive way to filter that query now
- 1:06
we can jump onto the component the first
- 1:10
thing we do is build an input field
- 1:12
where the user can enter their search
- 1:14
value
- 1:16
then we'll attach a function to the
- 1:18
keydown event which will run every time
- 1:21
the user presses the cubes field from
- 1:24
there we will populate an array of
- 1:26
movies and then loop through them using
- 1:28
the ng 4 directive and as the final
- 1:32
touch will add the ng-if directive to a
- 1:34
div that will only be displayed look the
- 1:36
movies array is empty in the component
- 1:40
type script we start by injecting the
- 1:42
service that we built earlier and we
- 1:44
also import the rxjs subject class now
- 1:50
we declare a couple variables the movies
- 1:52
variable is going to hold the firebase
- 1:54
list observable that start at and end at
- 1:57
variables both get a hold subject and


