new to angular animations here... I want to repeat a simple fade in animation on button click for two images. Each time the button is clicked, I want the old images to fade out and new images to fade in. Currently, after first click, images fade in. After second click, images fade out. I would like fade out and in to happen every click.
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('fade', [
state('startRound', style({opacity:1})),
state('endRound', style({opacity:0})),
transition('* <=> *',[
animate(500)
])
])
]
})
export class AppComponent {
public state:string = 'endRound';
changeState(){
this.state = this.state == 'startRound' ? 'endRound' : 'startRound';
}
onClick(){
this.changeState();
}
}
<p>
<img src="https://media.istockphoto.com/vectors/football-grunge-background-vector-id985653890" [@fade]=state>
<img src="https://media.istockphoto.com/vectors/football-grunge-background-vector-id985653890" [@fade]=state>
</p>
<button (click)="onClick()">Click Me</button>
https://stackblitz.com/edit/angular-ivy-fzpmwm?file=src/app/app.component.ts
Thanks