我这里有一个列表div
,我想在单击时滑动特定元素。目前所有元素都在滑动,因为状态是所有元素的单个变量。
.html
<div *ngFor="let item of [1,2,3,4,5]" [@slideOutAnimation]="state" (@slideOutAnimation.done)="onDone($event)">
<button (click)="DeleteItem(item)">Delete</button>
</div>
.ts
@Component({
selector: 'page-box',
templateUrl: 'box.html',
animations:[
trigger('slideOutAnimation', [
state('inactive',style({
transform: 'translateX(0%)'
})),
state('active',style({
transform: 'translateX(-200%)'
})),
transition('inactive => active', animate('500ms ease-out'))
])
]
})
export class BoxPage{
state:string = 'inactive';
DeleteItem(item){
this.state = 'active';
}
}