Consider this Angular animation trigger attached to a component:
trigger('fadeInOut', [
transition(':enter', [
style({ opacity: 0 }),
animate('500ms ease-in', style({ opacity: 1 }))
]),
transition(':leave', [
animate('500ms ease-out', style({ opacity: 0 }))
])
])What will the component do when it appears and disappears?
Look at the :enter and :leave transitions and their styles.
The :enter transition starts with opacity 0 and animates to opacity 1 over 500ms, creating a fade-in effect. The :leave transition animates opacity from current to 0 over 500ms, creating a fade-out effect.
Angular animations use the keyframes() function to define multiple steps. Which of these options is syntactically correct?
Remember that keyframes() takes an array of style() calls with offset values.
Option B correctly uses an array of style() objects with offset properties inside keyframes(). Other options misuse object syntax or omit offset.
Given this animation trigger:
trigger('slideIn', [
transition('void => *', [
animate('300ms ease-in', keyframes([
style({ transform: 'translateX(-100%)', offset: 0 }),
style({ transform: 'translateX(0)', offset: 1 })
]))
])
])The animation does not run when the component appears. What is the likely cause?
Check if the animation trigger is properly attached to the component's template.
If the animation trigger name is not used in the component's template (e.g., @slideIn on an element), Angular will not run the animation even if the trigger is defined.
Consider this Angular animation:
trigger('colorChange', [
transition('* => *', [
animate('1s', keyframes([
style({ backgroundColor: 'red', offset: 0 }),
style({ backgroundColor: 'blue', offset: 0.5 }),
style({ backgroundColor: 'green', offset: 1 })
]))
])
])After the animation finishes, what background color will the element have?
The last keyframe defines the final style after animation.
The animation ends at offset 1 with backgroundColor 'green', so the element's background color will be green after the animation.
Angular animations allow both simple style transitions and keyframe animations. Which reason best explains why you would choose keyframes?
Think about the flexibility keyframes provide compared to a start and end style.
Keyframes let you specify multiple style changes at different points in time, allowing more detailed and complex animations than simple start-to-end transitions.