We have a very simple component that should be faded in and out on :enter
and :leave
events:
import { Component, HostBinding } from '@angular/core';
import { animate, style, transition, trigger } from '@angular/animations';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
animations: [
trigger('host', [
transition(':enter', [
style({ opacity: 0 }),
animate('240ms linear', style({ opacity: 1 })),
]),
transition(':leave', [
style({ opacity: 1 }),
animate('240ms linear', style({ opacity: 0 })),
])
]),
]
})
export class TestComponent {
@HostBinding('@host') host() {
return true;
}
}
The component is used like this:
<app-test *ngIf="someBoolean"></app-test>
Now the animation on :enter
does run. But the element is not faded out, when the component is being removed (the variable someBoolean
becomes false
).
What is missing?