mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 14:01:20 +08:00
fix(VirtualScroll): initialise differ with trackByFn (#11492)
* fix(VirtualScroll): initialise differ with trackByFn * fix(VirtualScroll): DRY up differ initialization
This commit is contained in:

committed by
Manu MA

parent
646d736d07
commit
299a68bcdc
@ -234,6 +234,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
|
||||
};
|
||||
_queue: number = SCROLL_QUEUE_NO_CHANGES;
|
||||
_recordSize: number = 0;
|
||||
_virtualTrackBy: TrackByFn;
|
||||
|
||||
@ContentChild(VirtualItem) _itmTmp: VirtualItem;
|
||||
@ContentChild(VirtualHeader) _hdrTmp: VirtualHeader;
|
||||
@ -249,9 +250,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
|
||||
@Input()
|
||||
set virtualScroll(val: any) {
|
||||
this._records = val;
|
||||
if (isBlank(this._differ) && isPresent(val)) {
|
||||
this._differ = this._iterableDiffers.find(val).create(this.virtualTrackBy);
|
||||
}
|
||||
this._updateDiffer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -368,7 +367,12 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
|
||||
/**
|
||||
* @input {function} Same as `ngForTrackBy` which can be used on `ngFor`.
|
||||
*/
|
||||
@Input() virtualTrackBy: TrackByFn;
|
||||
@Input()
|
||||
set virtualTrackBy(val: TrackByFn) {
|
||||
if (!isPresent(val)) return;
|
||||
this._virtualTrackBy = val;
|
||||
this._updateDiffer();
|
||||
};
|
||||
|
||||
|
||||
constructor(
|
||||
@ -481,6 +485,12 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
|
||||
return null;
|
||||
}
|
||||
|
||||
private _updateDiffer(): void {
|
||||
if (isBlank(this._differ) && isPresent(this._records)) {
|
||||
this._differ = this._iterableDiffers.find(this._records).create(this.virtualTrackBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* DOM WRITE
|
||||
@ -632,7 +642,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
|
||||
var stopAtHeight = (data.scrollTop + data.renderHeight);
|
||||
|
||||
processRecords(stopAtHeight, records, cells,
|
||||
this._hdrFn, this._ftrFn, data);
|
||||
this._hdrFn, this._ftrFn, data);
|
||||
}
|
||||
|
||||
// ******** DOM READ ****************
|
||||
|
Reference in New Issue
Block a user