Fireship · @fireship

Angular Components Beginner's Guide

Uploaded June 20, 2018 · Length 13:52

Angular Components Beginner's Guide

Summary

This video teaches how to create and use Angular components, including binding data, events, and interpolation, and how to use directives like ngIf and ngFor.

  • angular components
  • angular beginner's guide
  • angular development
  • typescript
  • html templates
  • angular directives
  • ngif
  • ngfor

Transcript preview

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

  1. 0:00

    [Music]

  2. 0:06

    components are like the LEGO pieces of

  3. 0:08

    an angular application if you don't know

  4. 0:10

    how to put them together properly you're

  5. 0:11

    not going to be able to build anything

  6. 0:12

    cool over the next 10 minutes or so I'll

  7. 0:14

    show you all of the basics and angular

  8. 0:16

    components and how to piece them

  9. 0:18

    together in an application

  10. 0:19

    this video is beginner level so if you

  11. 0:21

    know a little bit about JavaScript and

  12. 0:23

    web development you should be okay if

  13. 0:25

    you're new to the channel make sure to

  14. 0:26

    LIKE and subscribe and grab the full

  15. 0:28

    write-up from angular firebase com the

  16. 0:31

    first question we need to answer is what

  17. 0:32

    is a component in the first place and I

  18. 0:35

    think the most simple answer to this

  19. 0:36

    question is that it's just a controller

  20. 0:38

    for the user interface as a developer

  21. 0:41

    you write components to control how your

  22. 0:42

    app is experienced by end-users to show

  23. 0:45

    you this in practice I'm opening a brand

  24. 0:47

    new angular 6 app that was generated

  25. 0:49

    with the CLI then I'm generating a new

  26. 0:52

    component called home which you'll

  27. 0:54

    notice creates four different files in

  28. 0:56

    the app directory the vast majority of

  29. 0:58

    the logic that you'll write will be in

  30. 1:00

    the home component ES file the component

  31. 1:03

    itself is just a typescript class but it

  32. 1:05

    uses this component decorator to

  33. 1:06

    sprinkle in some angular magic the most

  34. 1:09

    important thing is that it allows us to

  35. 1:11

    bind data from this typescript file to

  36. 1:13

    the HTML template the first thing I want

  37. 1:15

    to show you is how to bind typescript

  38. 1:17

    code to your HTML let's define a

  39. 1:19

    property on this class called clicked

  40. 1:21

    that defaults to false now let's go into

  41. 1:23

    the HTML and let's imagine we have a

  42. 1:25

    button that we want to disable after

  43. 1:27

    it's been clicked we combined our

  44. 1:29

    typescript data to this attribute in

  45. 1:31

    HTML by wrapping it in square brackets

  46. 1:33

    disabled isn't something angular

  47. 1:35

    provides it's an actual attribute on the

  48. 1:37

    HTML element which I'm looking at here

  49. 1:39

    in the Mozilla documentation the special

  50. 1:42

    thing about angular is that we can wrap

  51. 1:43

    this attribute in square brackets and

  52. 1:45

    then bind it to our type script so

  53. 1:47

    instead of just passing it a boolean

  54. 1:49

    value like false we can actually pass it

  55. 1:51

    our clicked property which we can then

  56. 1:52

    toggle on our typescript as needed it's

  57. 1:55

    currently set to false so we should be

  58. 1:56

    able to serve our app and the button

  59. 1:58

    should be clickable which it is if we go