Fireship · @fireship

Beautiful Router Animations with Angular

Uploaded February 11, 2019 · Length 10:01

Beautiful Router Animations with Angular

Summary

Implementing router animations in Angular for a polished app experience, including fade-in, slide, and keyframe animations.

  • angular router animations
  • beautiful animations
  • angular animations tutorial
  • router transitions
  • angular animation examples

Transcript preview

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

  1. 0:00

    [Music]

  2. 0:07

    an easy way to make your app more

  3. 0:08

    polished is to implement animations

  4. 0:10

    between router transitions today's video

  5. 0:12

    is a complete guide to router animations

  6. 0:13

    in angular and we'll build four

  7. 0:15

    different styles that range from a

  8. 0:16

    simple fadein to a complex key frame

  9. 0:18

    sequence of animations if you're new

  10. 0:20

    here like And subscribe and grab the

  11. 0:21

    full source code from fireship iio and

  12. 0:24

    before we get started I want to give a

  13. 0:25

    quick shout out to the deal crunch app

  14. 0:26

    which is a real estate app available on

  15. 0:28

    IOS and Android it was built by one of

  16. 0:30

    our Pro members and is a great example

  17. 0:31

    of what you can do with angular and

  18. 0:33

    ionic now let's first start by looking

  19. 0:35

    at the actual animations that we'll

  20. 0:37

    build in this video the first one is

  21. 0:38

    just a simple fade in which is applied

  22. 0:40

    to every single route in the app the

  23. 0:42

    second animation is a slide from left to

  24. 0:44

    right and it determines which direction

  25. 0:46

    to slide Based on data that we pass in

  26. 0:48

    through the router configuration the

  27. 0:50

    third one is slightly more complex and

  28. 0:51

    adds in Transformations so we can make

  29. 0:53

    the page kind of rotate in from the top

  30. 0:55

    corners and the fourth and final one

  31. 0:57

    uses key frames to create a sequence of

  32. 0:59

    style Chang es for example the new page

  33. 1:01

    comes in from the bottom and bumps the

  34. 1:03

    old page off and it spins and scales out

  35. 1:05

    of the screen I'm starting off here in

  36. 1:06

    my angular 7 app and you'll notice that

  37. 1:08

    I've generated a handful of components

  38. 1:10

    here just so we have something to

  39. 1:11

    actually route to and you don't need to

  40. 1:13

    do anything special with these

  41. 1:14

    components whatsoever so we won't even

  42. 1:16

    bother looking at them in this video

  43. 1:18

    then the other thing we'll do in the app

  44. 1:19

    module is import the browser animations

  45. 1:21

    module and add it to the Imports array

  46. 1:24

    from there we'll go into the HTML and

  47. 1:25

    the app component and create a main

  48. 1:27

    element and then Define an animation

  49. 1:29

    called route animations and then we'll

  50. 1:31

    point this to a method called prepare

  51. 1:33

    route which we'll Define in a second and

  52. 1:34

    its job is to determine which animation

  53. 1:36

    to apply to a given route now inside of

  54. 1:38

    this element we'll Define our router

  55. 1:40

    outlet and then give it a template

  56. 1:41

    variable name of outlet as well now

  57. 1:43

    whenever a route changes we can animate

  58. 1:45

    the content inside of the router Outlet

  59. 1:48

    then you can see above the outlet I have

  60. 1:49

    my actual navigation bar so this will

  61. 1:51

    stay fixed and not be animated between

  62. 1:53

    the route changes now I'll jump into the

  63. 1:54

    app component typescript and you'll see

  64. 1:56

    that I'm importing these animations

  65. 1:58

    which we have not yet defined I simp