⚠️ This lesson is retired and might contain outdated information.

Animate Between Angular States Using Transitions

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet

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.

[00:00] 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.

[00:24] 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.

[01:00] 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.