Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 972 of the free egghead.io lessons, plus get Angular 2 content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Animate Between Angular 2 States Using Transitions

1:11 Angular 2 lesson by

The foundation of animation in Angular 2 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.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

The foundation of animation in Angular 2 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.

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?