如何在 Angular2 中删除 dom 元素时触发动画?
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, Validators } from "@angular/forms";
import {
trigger,
state,
style,
animate,
transition
} from '@angular/animations';
import { ServerService } from './server.service';
@Component({
selector: 'fc-server',
templateUrl: './server.component.html',
animations: [
trigger('flyInFlyOut', [
state('*', style({transform: 'translateX(0)', opacity: 1})),
transition('void => *', [
style({transform: 'translateX(-100%)', opacity: 0}),
animate('400ms ease')
]),
transition('* => void', [
style({transform: 'translateX(-100%)'}),
animate('400ms ease')
])
])
]
})
export class Server {
@Input() serverInstance;
serverForm;
constructor(
private serverService: ServerService) {}
ngOnInit() {
this.serverForm = new FormGroup({
serverName: new FormControl('', Validators.required),
serverPort: new FormControl('', Validators.required),
serverIp: new FormControl('', Validators.required),
});
}
@Output() remove = new EventEmitter();
onRemove() {
this.serverService.remove(this.serverInstance);
}
onSubmit(serverInstance) {
this.serverService.add(serverInstance);
}
}
一切正常,从列表中删除项目,将项目添加到列表中,动画...除了删除项目时,列表项目被删除而没有动画。有什么见解吗?
这似乎是 Angular2 反复出现的问题,但据我所见,没有人真正有好的解决方案。