What is Angular animation?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
Angular's animation system is built on the Web Animations API and CSS transitions, providing a powerful DSL for defining component animations in TypeScript. Import: import { trigger, state, style, animate, transition, keyframes, query, stagger } from "@angular/animations";. Core concepts: trigger: gives the animation a name for binding in templates: @Component({ animations: [ trigger("fadeSlide", [ ... ]) ] }). Template binding: <div [@fadeSlide]="animationState">; state: defines styles for a named state: state("void", style({ opacity: 0, transform: "translateY(-20px)" })). void = element not in DOM; transition: defines animation between states: transition("void => *", animate("300ms ease-out")) (* = any state). Shorthand: transition(":enter", ...) (void → *), transition(":leave", ...) (* → void); animate: specifies duration, easing, delay: animate("300ms 100ms ease-in-out", style({ opacity: 1 })); keyframes: step-by-step animations; query/stagger: animate child elements with staggered timing. Common animations: enter/leave fade: add the trigger to the element, bind to a boolean. List item stagger animations with @for. Route transition animations: wrap router-outlet in a trigger based on route data. Angular Animations vs CSS: Angular animations are more programmatic (state-driven), better for conditional animations, and work with component data. CSS animations are simpler for basic effects.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Angular codebase.
Previous
What is Angular i18n (internationalization)?
Next
What is the Angular HttpClient interceptor and error handling?
More Angular Questions
View all →- Intermediate What is RxJS and how is it used in Angular?
- Intermediate What is the difference between switchMap, mergeMap, concatMap, and exhaustMap?
- Intermediate What is the difference between Subject, BehaviorSubject, ReplaySubject, and AsyncSubject?
- Intermediate What is the Angular NgRx state management library?
- Intermediate What is Angular lazy loading and preloading strategy?