在Angular 1.5中,track by不能与order by一起工作——期望的数组,但收到了

track by does not work with order by in Angular 1.5 - Expected array but received

本文关键字:by 期望 数组 工作 order Angular track 不能 一起      更新时间:2023-09-26

从Angular 1.4.11迁移到1.5.8后,我遇到了这个错误:

Error: [orderBy:notarray] Expected array but received: 3455

我在这个表达式中找到了它:

ng-options="profile.name for profile in vm.allProfiles track by profile.id | orderBy: 'name'"

但是当改成

ng-options="profile.name for profile in vm.allProfiles | orderBy: 'name'"

我还没有找到任何与突破性变化的关系。你知道发生了什么事吗?

在指定跟踪表达式之前,应该将过滤器应用于表达式(这里是Array)。因为orderBy过滤器适用于array而不是track by

ng-options="profile.name for profile in vm.allProfiles | orderBy: 'name' track by profile.id"