Fireship · @fireship

Angular Reactive Forms with Firebase Database Backend

Uploaded August 1, 2017 · Length 5:53

Angular Reactive Forms with Firebase Database Backend

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.

  1. 0:00

    angular's reactive form module allows

  2. 0:02

    you to build reliable yet complex forms

  3. 0:05

    throughout your application in this

  4. 0:06

    episode we're going to talk about how to

  5. 0:08

    use the reactive form module along with

  6. 0:10

    the Firebase real-time database what

  7. 0:13

    we're building is just a simple form for

  8. 0:14

    classified ads rather than use a

  9. 0:17

    traditional form submit button we're

  10. 0:18

    going to update the form in the database

  11. 0:21

    anytime a value changes in my opinion

  12. 0:23

    this provides a better user experience

  13. 0:25

    and it also prevents data from being

  14. 0:27

    lost if the page is refreshed so what is

  15. 0:30

    a reactive form basically it's just a

  16. 0:32

    form that's been defined in the

  17. 0:33

    component typescript to give it a

  18. 0:35

    synchronous flow of data this gives you

  19. 0:38

    better control over logic and validation

  20. 0:40

    as well as making testing a lot easier

  21. 0:43

    the other type of form is a template

  22. 0:44

    driven form which uses NG model to build

  23. 0:47

    the form in the component HTML the

  24. 0:50

    benefit is that you can create forms

  25. 0:51

    with less code however the drawback is

  26. 0:54

    that they're harder to maintain

  27. 0:55

    especially as the form grows larger and

  28. 0:57

    more complex so A good rule to follow is

  29. 0:59

    if you're building a big complex form

  30. 1:02

    you should probably go with the reactive

  31. 1:04

    form module reactive forms are kept in

  32. 1:06

    their own module so we'll need to import

  33. 1:08

    that in whichever module we plan on

  34. 1:10

    using it in in this example we import

  35. 1:12

    the reactive forms module into our app

  36. 1:15

    module and then add it to the import

  37. 1:17

    section now we can start building the ad

  38. 1:20

    service that will get data from Firebase

  39. 1:22

    for our classified ads I'm also going to

  40. 1:24

    create an ad listing class which will

  41. 1:26

    populate some default data whenever we

  42. 1:28

    start a new ad from scratch so our

  43. 1:30

    classified ads will have a title some

  44. 1:32

    content a price and an image from there

  45. 1:36

    we can inject the angular fire database

  46. 1:38

    and then we'll create a function that

  47. 1:40

    will create a new ad in the database

  48. 1:42

    this function will push a new ad listing

  49. 1:44

    to a Firebase list observable but

  50. 1:46

    instead of returning that full list

  51. 1:48

    observable we'll just grab the key and

  52. 1:50

    then return the newly created object as

  53. 1:52

    an object observable you can call Key

  54. 1:56

    after you call push and that'll return

  55. 1:57

    the push key from Firebase then you can