angular - 对使用 ngFor 显示的数组进行排序会应用 void 动画状态
问题描述
<ul>
<li *ngFor="let user of users; trackBy: identify; index as i" [@anim]="user.id" (@anim.done)="test($event)">
{{user.name}} (@{{user.id}})
</li>
</ul>
constructor() {
this.change1();
}
change1(): void {
this.users = [user1, user2, user3, user4, user5];
}
change2(): void {
this.users = [user2, user1, user3, user4, user5];
}
identify(index: number, item: User) {
return item.id;
}
test(e) {
console.log(e);
}
const user1 = { id: 1, name: 'one' };
const user2 = { id: 2, name: 'two' };
const user3 = { id: 3, name: 'three' };
const user4 = { id: 4, name: 'four' };
const user5 = { id: 5, name: 'five' };
https://stackblitz.com/edit/angular-ivy-h7ohwc?file=src/app/app.component.html
这个例子说明了这个问题。我们有一个使用 trackBy + 每个元素都有动画的数组。在控制台中对数组(按钮 change2)进行排序后,您可以看到元素 2 将状态从 2 更改为 void。如果它不改变,是否有可能获得状态 2?为什么会变废为宝?
解决方案
推荐阅读
- javascript - PHPMailer 发送重复的电子邮件
- amazon-redshift - 如何在 Redshift 中创建返回语句
- java - Java中的矩形重叠
- swift - 从 postId firebase 和 swift 获取帖子
- laravel - 调用控制器方法是一种好习惯吗?
- spring-boot - 在插入之前查询弹性搜索
- module - 当使用模块变量作为输入变量时,有没有办法像我们对子程序变量一样指定 intent(in) 属性?
- python - 如何让 django-ldapdb 将数据源识别为 LDAP
- java - SQLite 查询未创建表;没有产生错误
- c - C - 混合文本文件数据 > 到不同的数组(Int 和 String)