[ionic2] virtualTrackBy seem to not be working
See original GitHub issueI was looking for some optimisation in my app then i stumble uppon something weird. In my template i’ve done this:
<ion-content>
<ion-list [virtualScroll]="storeStands.collection$ | async"
[virtualTrackBy]="trackStand"
[headerFn]="alphabetical" >
<ion-item-divider *virtualHeader="let header">{{ header }}</ion-item-divider>
<a ion-item text-wrap
*virtualItem="let stand"
[navPush]="[standPage, { stand: stand }]">
<h2>{{ stand.organization }}</h2>
</a>
</ion-list>
</ion-content>
In my controller
trackStand(index, stand: Stand) {
console.log(index, stand);
return stand.id;
}
Putting a console log in trackStand
function but it’s never called (as opposed with ngForTrackBy).
Explorating futher i put a console.log(val)
inside the ionic-angular/components/virtual-scroll/virtual-scroll.js:305
to see if my parameter was listened, and i get undefined
.
set: function (val) {
this._trackBy = val;
}
Moving back to my template i set [virtualTrackBy]="'trackStand'"
and i then get 'trackStand'
inside virtual-scroll.js:306
.
But was more curious an tracked where this._trackBy
was used, in the same file virtual-scroll.js:260
inside a condition.
set: function (val) {
this._records = val;
if (util_1.isBlank(this._differ) && util_1.isPresent(val)) {
this._differ = this._iterableDiffers.find(val).create(this._cd, this._trackBy);
}
}
I put console.log(this._trackBy, this._differ)
inside that condition and surprise, this._trackBy
is undefined and this._differ
has a method _trackByFn
with attribute name: 'trackByIdentity'
.
Putting the console.log
just before the condition, the this._trackBy
display two times, one with undefined
and one with 'trackStand'
, this._differ
doesn’t change at all.
A final test was to remove the condition if (util_1.isBlank(this._differ) && util_1.isPresent(val))
and there this._differ._trackByFn.name
was empty when [virtualTrackBy]="trackStand"
and only there it work as expected.
So my conclusion is, when this._differ
is set, and even if val
change, this._differ
isn’t changed, and doesn’t take in account this._trackBy
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:16 (3 by maintainers)
+1
Any update about this issue? I have the same problem with ionic 2.0.0 RC4, [virtualTrackBy]=“trackStand” does not execute, if (util_1.isBlank(this._differ) && util_1.isPresent(val)) condition it’s alway false.