0
0
Angularframework~20 mins

Enter and leave animations in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Animation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when this Angular animation triggers on element enter?
Consider this Angular animation trigger for an element entering the DOM:
trigger('fadeIn', [
  transition(':enter', [
    style({ opacity: 0 }),
    animate('500ms ease-in', style({ opacity: 1 }))
  ])
])

What will the element's opacity be immediately after it finishes entering?
AThe element will have opacity 0, fully transparent.
BThe element will have opacity 1, fully visible.
CThe element will have opacity 0.5, semi-transparent.
DThe element will have no opacity style applied.
Attempts:
2 left
💡 Hint
Think about what the final style in the animate() function sets.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a leave animation in Angular?
You want to animate an element fading out when it leaves the DOM. Which animation trigger code is correct?
Atransition(':leave', [animate('300ms', style({ opacity: 0 }))])
Btransition('leave', [animate('300ms', style({ opacity: 0 }))])
Ctransition(':exit', [animate('300ms', style({ opacity: 0 }))])
Dtransition('leave', [style({ opacity: 0 }), animate('300ms')])
Attempts:
2 left
💡 Hint
Angular uses special keywords for enter and leave states.
🔧 Debug
advanced
2:00remaining
Why does this Angular leave animation not run?
Given this animation trigger:
trigger('slideOut', [
  transition(':leave', [
    animate('400ms ease-out', style({ transform: 'translateX(100%)' }))
  ])
])

And this template:
<div *ngIf="show" @slideOut>Slide me out</div>

When 'show' becomes false, the element disappears instantly without animation. Why?
AThe transition should use ':enter' instead of ':leave'.
BThe animation syntax is incorrect; transform should be in quotes.
CThe trigger name 'slideOut' does not match the template binding.
DThe element is removed before the animation can start because Angular destroys it immediately.
Attempts:
2 left
💡 Hint
Angular removes elements immediately unless animations are properly hooked.
state_output
advanced
2:00remaining
What is the final style state after this enter and leave animation?
Consider this Angular animation trigger:
trigger('fadeToggle', [
  transition(':enter', [
    style({ opacity: 0 }),
    animate('200ms', style({ opacity: 1 }))
  ]),
  transition(':leave', [
    animate('200ms', style({ opacity: 0 }))
  ])
])

If the element is shown and then hidden, what opacity style will it have after the leave animation completes?
AOpacity 0, fully transparent but still in the DOM.
BOpacity 1, fully visible because leave animation does not change it.
CNo opacity style because the element is removed from the DOM.
DOpacity 0.5, halfway transparent.
Attempts:
2 left
💡 Hint
What happens to elements after leave animations finish?
🧠 Conceptual
expert
3:00remaining
How does Angular coordinate multiple animations on nested elements during enter and leave?
You have a parent element with an enter animation and a child element with its own enter animation. When the parent enters, how does Angular handle the child's animation timing?
AAngular runs the parent's and child's enter animations in parallel by default.
BAngular waits for the parent's animation to finish before starting the child's animation.
CAngular ignores the child's animation if the parent has one.
DAngular runs the child's animation first, then the parent's.
Attempts:
2 left
💡 Hint
Think about how Angular treats nested animations by default.