Fireship · @fireship

Top 7 RxJS Concepts for Angular Developers

Uploaded July 21, 2017 · Length 7:19

Top 7 RxJS Concepts for Angular Developers

Summary

rxjs library concepts for angular developers, including combine latest, static methods, subscriptions, mapping observables, switch map, combine latest, and behavior subjects.

  • rxjs concepts
  • angular developers
  • rxjs library
  • combine latest operator
  • static methods rxjs
  • angular subscriptions
  • observable mapping
  • switch map operator

Transcript preview

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

  1. 0:00

    rxjs is a huge library with a very steep

  2. 0:03

    learning curve in this episode I'm going

  3. 0:05

    to talk about a few key Concepts that

  4. 0:07

    are specific to angular Firebase

  5. 0:09

    developers I believe it's best to focus

  6. 0:12

    on what you actually need to learn

  7. 0:13

    rather than try to master the entire

  8. 0:15

    rxjs library to do this I've created a

  9. 0:18

    simple component that uses the angular

  10. 0:20

    Fire 2 package to retrieve cats and dogs

  11. 0:23

    from Firebase cats and dogs each have

  12. 0:25

    their own collection and there's another

  13. 0:27

    collection for humans which represent

  14. 0:29

    the owner of a given pet your component

  15. 0:32

    should look something like this we

  16. 0:33

    import the angular fire database and

  17. 0:35

    then inject it in the Constructor when

  18. 0:38

    using rxjs and angular you only import

  19. 0:40

    the methods and classes that you need in

  20. 0:43

    rxjs there are two types of methods

  21. 0:45

    static and instance in this first

  22. 0:47

    example we use an instance method

  23. 0:49

    combine latest so we create two

  24. 0:51

    instances of an

  25. 0:53

    observable then we can use that operator

  26. 0:55

    on the observable instance itself notice

  27. 0:57

    how the method was imported from ad SL

  28. 1:00

    operator the operator directory contains

  29. 1:03

    all of the instance methods it's not

  30. 1:05

    important to know at this point but

  31. 1:06

    using combined latest will result in an

  32. 1:09

    observable array of two strings now

  33. 1:11

    let's accomplish the same thing using a

  34. 1:14

    static method to obtain the static

  35. 1:16

    method we import from the add/

  36. 1:18

    observable

  37. 1:19

    directory instead of calling the method

  38. 1:21

    on an instance we call it on the

  39. 1:23

    observable class itself and then we pass

  40. 1:25

    the two observables to it as arguments

  41. 1:28

    in rxjs some methods are only instance

  42. 1:30

    others are only static and some overlap

  43. 1:32

    for both now let's talk about

  44. 1:35

    subscriptions that's how you actually

  45. 1:36

    extract data from observables there are

  46. 1:39

    two main ways to do this in angular you

  47. 1:40

    can either subscribe in the component

  48. 1:42

    typescript or in the component HTML in

  49. 1:45

    this example we will subscribe to cats

  50. 1:47

    in the HTML and dogs in the component

  51. 1:50

    typescript notice how cats are a

  52. 1:52

    Firebase list observable and dogs are

  53. 1:54

    just a regular array calling DB list

  54. 1:57

    will return in observable from the

  55. 1:59

    Firebase database for cats we just keep