Fireship · @fireship

Loading Spinners for Asynchronous Firebase Data

Uploaded May 1, 2017 · Length 2:31

Loading Spinners for Asynchronous Firebase Data

Summary

display and hide loading spinner with firebase data in angular

  • firebase loading spinner
  • angular async data
  • loading indicators
  • angular fire
  • ui components

Transcript preview

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

  1. 0:00

    in this episode I will show you how to

  2. 0:02

    display and hide a loading spinner when

  3. 0:04

    retrieving a synchronous fire-based data

  4. 0:07

    from an angular application loading

  5. 0:09

    indicators are an important user

  6. 0:11

    interface feature because they show the

  7. 0:13

    end user when more data is incoming step

  8. 0:17

    1 create the spinner component we're

  9. 0:20

    going to create a spinner component that

  10. 0:22

    can be reused throughout the application

  11. 0:24

    to make it look cool I'm going to use

  12. 0:26

    the spin kit CSS library which can just

  13. 0:29

    be copied directly into the components

  14. 0:31

    CSS and HTML files at this point you

  15. 0:34

    don't need to change anything in the

  16. 0:35

    components typescript step to retrieve

  17. 0:43

    asynchronous data we need to load some

  18. 0:46

    data from firebase in order to make use

  19. 0:48

    of the spinner in this example I'm

  20. 0:50

    loading a firebase list observable via

  21. 0:53

    the angular fire to package the actual

  22. 0:56

    data is just an array of items from a

  23. 0:58

    to-do list this code is originally

  24. 1:01

    created for the real-time database video

  25. 1:03

    so check out it if you want to learn

  26. 1:05

    more about asynchronous data streams

  27. 1:06

    from firebase step 3 the show and hide

  28. 1:13

    the spinner we want to show the spinner

  29. 1:16

    in the items list component when the

  30. 1:18

    data is being retrieved

  31. 1:20

    first we define a variable called show

  32. 1:23

    spinner in the component and set it to

  33. 1:26

    true by default during the ng on a net

  34. 1:29

    life cycle so the data is requested from

  35. 1:33

    the service as the firebase lists

  36. 1:35

    observable we can determine if the data

  37. 1:38

    has been loaded by subscribing to it the

  38. 1:41

    function inside the subscribed call will

  39. 1:43

    be executed after the observable emits

  40. 1:45

    some data so we can simply set the show

  41. 1:49

    spinner variable to false once this

  42. 1:50

    happens in the template we can use the

  43. 1:56

    ng-if directive with the show spinner

  44. 1:58

    variable to control the visibility of