Fireship · @fireship

Learn Angular Animations with 5 Examples

Uploaded July 24, 2017 · Length 7:02

Learn Angular Animations with 5 Examples

Summary

Learn Angular animations with 5 examples, including fade-in/fade-out, photo gallery, and list animations, covering concepts like triggers, transitions, and keyframes.

  • angular animations
  • angular 4.2
  • css3 animations
  • web animations api
  • animation examples
  • angular tutorials

Transcript preview

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

  1. 0:00

    animation is often the x-factor that

  2. 0:02

    separates remarkable apps from ordinary

  3. 0:05

    apps in this episode I'm going to cover

  4. 0:07

    five different concepts related to

  5. 0:09

    angular animations including a few new

  6. 0:11

    concepts that were introduced in angular

  7. 0:13

    4.2 angular animations are built on the

  8. 0:17

    web animations API which is very similar

  9. 0:20

    to css3 animations if you're not

  10. 0:23

    comfortable with animation at all I

  11. 0:25

    recommend doing some practice with css3

  12. 0:27

    first and then you'll be able to make

  13. 0:28

    the most out of angular's animation

  14. 0:30

    module the first step to get started is

  15. 0:34

    to import the browser animation module

  16. 0:36

    into whatever module you plan on using

  17. 0:38

    animations in this first example I'm

  18. 0:41

    going to create a fade-in fade-out

  19. 0:42

    animation that will show some content in

  20. 0:45

    a popover when a button is clicked we

  21. 0:47

    import the methods we need from the

  22. 0:49

    animation module and then we'll create a

  23. 0:51

    boolean variable show that will

  24. 0:53

    determine the visibility of the popover

  25. 0:55

    I also create a getter called state name

  26. 0:58

    which will return the boolean variable

  27. 1:00

    as a string either show or hide which we

  28. 1:02

    need when defining the animation itself

  29. 1:03

    in the HTML we use animations by

  30. 1:07

    prefixing the animation name with the @

  31. 1:10

    symbol and then pass at the current

  32. 1:11

    state of whatever variable we're going

  33. 1:14

    to animate in this case the only

  34. 1:16

    possible values will be show or hide and

  35. 1:18

    then we add a button for the user to

  36. 1:20

    toggle this variable the end result

  37. 1:24

    should look something like this it's

  38. 1:25

    just a simple div that fades in and

  39. 1:27

    fades out when that button is clicked

  40. 1:29

    every component has an animations

  41. 1:31

    property which accepts an array first we

  42. 1:34

    pass it a trigger which corresponds to

  43. 1:36

    the name with the @ symbol in the HTML

  44. 1:39

    then we define how each state should

  45. 1:41

    look once the animation is complete when

  46. 1:43

    that popover is being shown the opacity

  47. 1:45

    is 1 when it's hidden the opacity of 0

  48. 1:48

    to actually make this animate we need to

  49. 1:51

    define a transition which sets the time

  50. 1:53

    parameter for the animation to occur in

  51. 1:55

    this case when we transition from show

  52. 1:58

    to hide it will animate in 600

  53. 1:59

    milliseconds and ease out and then when