Concept Flow - Transition between states
Initial State
Trigger Event
Start Transition
Apply Animation
Update State
Render New State
Transition Complete
Shows how Angular moves from one UI state to another using animations triggered by events.
import { Component } from '@angular/core'; import { trigger, state, style, transition, animate } from '@angular/animations'; @Component({ selector: 'my-component', template: `<div [@openClose]="isOpen ? 'open' : 'closed'" (click)="toggle()">Toggle Panel</div>`, animations: [ trigger('openClose', [ state('open', style({ height: '200px', opacity: 1 })), state('closed', style({ height: '100px', opacity: 0.5 })), transition('open <=> closed', [animate('0.5s ease-in-out')]) ]) ] }) export class MyComponent { isOpen = true; toggle() { this.isOpen = !this.isOpen; } }
| Step | Trigger/Event | Current State | Action | Next State | Animation Applied |
|---|---|---|---|---|---|
| 1 | Component loads | open | Render initial state | open | No animation (initial) |
| 2 | User clicks toggle | open | Start transition to closed | closed | Animate height and opacity over 0.5s |
| 3 | Animation running | transition open->closed | Apply styles gradually | transition open->closed | Height shrinks, opacity fades |
| 4 | Animation ends | closed | Render final closed state | closed | Animation complete |
| 5 | User clicks toggle | closed | Start transition to open | open | Animate height and opacity over 0.5s |
| 6 | Animation running | transition closed->open | Apply styles gradually | transition closed->open | Height grows, opacity increases |
| 7 | Animation ends | open | Render final open state | open | Animation complete |
| 8 | No further events | open | Idle | open | No animation |
| Variable | Start | After Step 2 | After Step 4 | After Step 5 | After Step 7 | Final |
|---|---|---|---|---|---|---|
| isOpen | true | false | false | true | true | true |
Angular state transitions use triggers and animations. Define states with styles. Use transitions to animate between states. Trigger animations on events like clicks. Animations run smoothly changing styles over time.