Fireship · @fireship

Reactive Forms - The Basics

Uploaded May 22, 2018 · Length 15:48

Reactive Forms  - The Basics

Summary

Learn how to create reactive forms in Angular 6 with examples of form controls, validation, and dynamic form fields.

  • angular reactive forms
  • angular form controls
  • form validation angular
  • dynamic form fields angular
  • angular material forms

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:02

    today I'm going to show you everything

  3. 0:04

    you need to know to start using reactive

  4. 0:05

    forms in angular 6 effectively we'll do

  5. 0:08

    this by building five different forms

  6. 0:10

    that started the absolute basics then

  7. 0:12

    progress on to topics like dynamic form

  8. 0:14

    fields validation and submitting your

  9. 0:16

    form data to a back-end database almost

  10. 0:19

    all apps use forms in some capacity so

  11. 0:21

    understanding reactive forms is a very

  12. 0:23

    valuable skill to have as an angular

  13. 0:25

    developer if you're new make sure to

  14. 0:27

    subscribe and grab the source code from

  15. 0:29

    angular firebase comm and I'll be giving

  16. 0:31

    away three free hats on Friday all you

  17. 0:33

    have to do is leave a comment on this

  18. 0:34

    video I'll be starting off here from an

  19. 0:37

    angular 6 project and the first thing

  20. 0:39

    I'll do is add angular material to this

  21. 0:41

    project because it has some awesome UI

  22. 0:43

    elements for form validation you can

  23. 0:46

    install it in your project by running ng

  24. 0:48

    add angular slash material then I've

  25. 0:51

    already generated five different

  26. 0:52

    components that I'm going to use to

  27. 0:53

    demonstrate these different reactive

  28. 0:55

    form examples if you don't know how to

  29. 0:57

    generate components with the CLI make

  30. 0:59

    sure to watch episode 104 from last week

  31. 1:01

    the reactive forms module isn't included

  32. 1:04

    by default so we're going to import that

  33. 1:06

    from angular forms and then we have a

  34. 1:09

    bunch of modules that were importing

  35. 1:10

    from angular material that handled

  36. 1:12

    different form fields that we want to

  37. 1:14

    use then all of these modules will be

  38. 1:16

    added down to the import section giving

  39. 1:18

    us access to these various components

  40. 1:20

    and services when it comes to angular

  41. 1:22

    material there's a whole bunch of

  42. 1:23

    different form elements that you can use

  43. 1:25

    so make sure to check out the docs and

  44. 1:27

    experiment with some of the examples

  45. 1:28

    there

  46. 1:29

    the first reactive form we'll build

  47. 1:31

    starts with the absolute basics let's

  48. 1:34

    see how we can set up a few form

  49. 1:35

    controls for an email a message and a

  50. 1:38

    select field for a career then we'll

  51. 1:40

    observe the changes to the actual values

  52. 1:42

    being entered into this form you'll

  53. 1:45

    notice that every time we enter

  54. 1:46

    something into this form it updates the

  55. 1:48

    value object that's because under the

  56. 1:50

    hood the form is using rxjs to treat the

  57. 1:53

    form as a reactive real-time stream

  58. 1:55

    let's go ahead and jump into the type

  59. 1:58

    script for this component and we'll take

  60. 1:59

    a look at what we need to build the