I have made a very simple animation : on click on a div, it should collapse/expand and display different content.
I have mocked the behavior here : https://stackblitz.com/edit/animations-opacity-issue?file=src/app/app.component.ts
When you click on the div, it collapses as expected, but the teal div should fade out, while the crimson div should fade in.
Currently none work, and I don't know why.
import { Component } from '@angular/core';
import { animate, query, state, style, transition, trigger } from '@angular/animations';
@Component({
selector: 'my-app',
template: `
<div class="menu-container" [@menuSize]="isMenuExpanded" (click)="isMenuExpanded = !isMenuExpanded">
<div style="background-color: teal" *ngIf="isMenuExpanded" @menuVisibility></div>
<div style="background-color: crimson" *ngIf="!isMenuExpanded" @menuVisibility></div>
</div>
`,
styles: [`
.menu-container {
height: 100%;
background: coral;
width: 300px;
position: relative;
}
.menu-container div {
height: 200px;
width: 100%;
position: absolute;
}
`],
animations: [
trigger('menuSize', [
state('true', style({ width: '*' })),
state('false', style({ width: '100px' })),
transition('true <=> false', [
animate('500ms ease-in-out'),
]),
]),
trigger('menuVisibility', [
state('*', style({ opacity: '1' })),
state('void', style({ opacity: '0' })),
transition(':enter', [animate('300ms ease-in-out')]),
transition(':leave', [animate('300ms 500ms ease-in-out')])
])
],
})
export class AppComponent {
isMenuExpanded = true;
}