Which of the following is the main advantage of using Angular animations over plain CSS animations?
Think about how Angular integrates animations with its component system.
Angular animations are tightly integrated with Angular's component lifecycle and state management, allowing animations to trigger on state changes and events within Angular. CSS animations are more static and less aware of Angular's internal states.
Consider an Angular component with a trigger that animates when a boolean state changes. What is the expected behavior when the state toggles from false to true?
animations: [trigger('openClose', [state('open', style({height: '200px'})), state('closed', style({height: '100px'})), transition('closed => open', [animate('0.5s ease-in')]), transition('open => closed', [animate('0.3s ease-out')])])]
Look at the transition timing and styles defined for the state change.
The animation triggers on the state change from 'closed' to 'open', smoothly changing the height from 100px to 200px over 0.5 seconds as defined by the animate() function.
Which lifecycle hook is best suited to trigger logic after an Angular animation finishes?
Angular animations emit events you can listen to.
Angular animations emit events such as 'done' when an animation finishes. You can bind to these events using (@triggerName.done) in the template to run code after the animation completes.
Which option shows the correct way to define an Angular animation trigger named 'fadeIn' that changes opacity from 0 to 1 over 1 second?
Check the order of parameters in animate() and if style() is needed inside animate().
Option D correctly uses animate('1s ease-in') to animate from the void state (opacity 0) to the default style (opacity 1) on enter. The style inside animate() is optional if the final style is defined in the state or element.
Given this animation trigger, why does the animation not run when the component loads?
animations: [trigger('slideIn', [state('void', style({transform: 'translateX(-100%)'})), transition('void => *', [animate('0.5s ease-out')])])]Check if the animation trigger is applied in the template.
Defining an animation trigger alone does not run it. The trigger must be bound to an element in the template using [@slideIn]. Without this binding, the animation will not run on component load.