所以,我想通了。isDeleted
设置在 *ngFor 中的所有元素上。您应该在对象上有一个属性,如下所示:task.deleted = true
并使用它。
动画呢,我按照官方文档。
这是我的代码:
import {Component, Input, Output, EventEmitter,
trigger,
state,
style,
transition,
animate} from "@angular/core";
@Component({
selector: "vb-tasks-item",
animations: [
trigger('taskState', [
state('inactive', style({opacity: 1, transform: 'translateX(0) scale(1)'})),
state('active', style({opacity: 1, transform: 'translateX(0) scale(1)'})),
state('void', style({opacity: 0, display: 'none', transform: 'translateX(0) scale(1)'})),
transition('* => void', [
animate('1s 8 ease-out', style({
opacity: 0,
transform: 'translateX(0) scale(0.5)'
}))
])
])
],
template: `
<div class="vb-task-card" @taskState="task.deleted">
</div>`
export class TasksItemComponent {
@Input() public task: TaskSummary;
@Output() public deleteTask = new EventEmitter();
public onDeleteTask(task) {
task.deleted = (task.deleted === 'active' ? 'inactive' : 'active');
this.deleteTask.emit(task);
}
}
如果用户确认删除,我正在设置动画状态(task.deleted):
public onDeleteModal(isOk) {
this.isModalOpen = isOk;
if(isOk) {
this.tasksSandbox.deleteTask(this.taskToDelete.id)
.subscribe(res => {
if (res) {
this.taskToDelete.deleted = 'void';
this.isModalOpen = !isOk;
}
});
}else{
this.taskToDelete.deleted = 'inactive';
}
}