I want to fade out an element's child, by animating its opacity. It's working fine, but at the end of the animation, the child's style is reverted back to it's original state (opacity un-set).
How can this be prevented / how can I tell Angular to leave the style in the target state once the animation has completed?
Here's my code:
@Component({
selector: 'app-playground',
template: `
<div [@simpleStateTransition]="simpleState">
{{ simpleState }}
<div class="fadeout">fade this child out!</div>
</div>
<button (click)="toggleSimpleState()">toggle simple state</button>
`,
animations: [
trigger('simpleStateTransition', [
transition('initial => extended', group([
query('.fadeout', animate('300ms', style({'opacity': '0'})))
])),
])
]
})
export class PlaygroundComponent {
simpleState = 'initial'
constructor() { }
toggleSimpleState() {
this.simpleState = this.simpleState === 'initial' ? 'extended' : 'initial'
}
}