I'd like to animate an image swap in an angular 4 app. As the controller replaces the img src property the old image should fade away and the new appear.
In AngularJS this was possible by changing the opacity with ng-animate-swap. However, Angular 4 doesn't seem to support animate-swap. How can this be achieved without a swap trigger?
I've tried adding transitions from void to * and back for the src property but this doesn't work as expected. The first image is animated in, later the exchanges happen without animation.
@Component({
selector: 'app-play-card',
template: '<div (click)="loadImg()"><img [@fade]="imgsrc" src="{{ imgsrc }}" /></div>',
styleUrls: ['./play-card.component.css'],
animations: [
trigger('fade', [
transition('void => *', [
style({opacity: 0.1}),
animate(5000, style({opacity: 1}))
]),
transition('* => void', [
style({opacity: 0.9}),
animate(5000, style({opacity: 0}))
])
])
]
})