演示:https ://plnkr.co/edit/yfSdg1qoYz3oHzLWfG1U?p=preview
您可以使用 *ngIf 和setTimeout
一起来实现它。
我keyframes
用来添加动画。
animations: [
trigger('hasSaved', [
transition('void => *', [
animate(1000, keyframes([
style({opacity: 0, transform: 'translateX(-10%)', offset: 0}),
style({opacity: 1, transform: 'translateX(-40px)', offset: 0.3}),
style({opacity: 1, transform: 'translateX(0)', offset: 1.0})
]))
]),
transition('* => void', [
animate(1000, keyframes([
style({opacity: 1, transform: 'translateX(0)', offset: 0}),
style({opacity: 1, transform: 'translateX(30px)', offset: 0.3}),
style({opacity: 1, transform: 'translateX(20%)', offset: 1.0})
]))
])
])
]
export class App {
showSave:boolean=false;
title = 'app works!';
save(){
this.showSave=!this.showSave;
setTimeout(()=>{
this.showSave=!this.showSave;
},2000)
}
}