Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Animate Between Angular States Using Transitions

    2 - ~8.1.1

    The foundation of animation in Angular is using transitions to move from one state to another state. Transitions bring in the concept of time and how long it should take to go from one state to the next while they almost magically calculate the difference in values over time between the CSS properties of each state.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Now, we can make a second button here. We'll call this onStopClick(), call this stop. Create a method called onStopClick() and this .signal = stop. Now we'll have a go, stop, go, stop button. What we can do between these two states is we can define what's called a transition between the states.

    The way we define this transition is with a string that represents the from and it moves to the to. We're saying from any state and moving to any state. We want to animate for 500 milliseconds. Hit save and you'll see we go from Go to Stop, Go to Stop, and it's smoothly animating between red and green. I can even add in more properties here, like height 100 pixels, height 50 pixels.

    Now when it starts, you'll see it goes from nothing to Stop, and then Go, and Stop and Go, and smoothly animating between those states and properties.