Fireship · @fireship
Angular Reactive Forms with Firebase Database Backend
Uploaded August 1, 2017 · Length 5:53
Summary
Angular Reactive Forms with Firebase Database Backend tutorial for building reliable complex forms
- angular reactive forms
- firebase database backend
- complex forms
- form validation
- angular forms tutorial
- firebase angular tutorial
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
angular's reactive form module allows
- 0:02
you to build reliable yet complex forms
- 0:05
throughout your application in this
- 0:06
episode we're going to talk about how to
- 0:08
use the reactive form module along with
- 0:10
the Firebase real-time database what
- 0:13
we're building is just a simple form for
- 0:14
classified ads rather than use a
- 0:17
traditional form submit button we're
- 0:18
going to update the form in the database
- 0:21
anytime a value changes in my opinion
- 0:23
this provides a better user experience
- 0:25
and it also prevents data from being
- 0:27
lost if the page is refreshed so what is
- 0:30
a reactive form basically it's just a
- 0:32
form that's been defined in the
- 0:33
component typescript to give it a
- 0:35
synchronous flow of data this gives you
- 0:38
better control over logic and validation
- 0:40
as well as making testing a lot easier
- 0:43
the other type of form is a template
- 0:44
driven form which uses NG model to build
- 0:47
the form in the component HTML the
- 0:50
benefit is that you can create forms
- 0:51
with less code however the drawback is
- 0:54
that they're harder to maintain
- 0:55
especially as the form grows larger and
- 0:57
more complex so A good rule to follow is
- 0:59
if you're building a big complex form
- 1:02
you should probably go with the reactive
- 1:04
form module reactive forms are kept in
- 1:06
their own module so we'll need to import
- 1:08
that in whichever module we plan on
- 1:10
using it in in this example we import
- 1:12
the reactive forms module into our app
- 1:15
module and then add it to the import
- 1:17
section now we can start building the ad
- 1:20
service that will get data from Firebase
- 1:22
for our classified ads I'm also going to
- 1:24
create an ad listing class which will
- 1:26
populate some default data whenever we
- 1:28
start a new ad from scratch so our
- 1:30
classified ads will have a title some
- 1:32
content a price and an image from there
- 1:36
we can inject the angular fire database
- 1:38
and then we'll create a function that
- 1:40
will create a new ad in the database
- 1:42
this function will push a new ad listing
- 1:44
to a Firebase list observable but
- 1:46
instead of returning that full list
- 1:48
observable we'll just grab the key and
- 1:50
then return the newly created object as
- 1:52
an object observable you can call Key
- 1:56
after you call push and that'll return
- 1:57
the push key from Firebase then you can


