fix(virtual-list): virtualTrackBy reference

This commit is contained in:
Manuel Mtz-Almeida
2017-05-05 00:24:33 +02:00
parent 299a68bcdc
commit de19dbe81b

View File

@ -240,7 +240,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
@ContentChild(VirtualHeader) _hdrTmp: VirtualHeader; @ContentChild(VirtualHeader) _hdrTmp: VirtualHeader;
@ContentChild(VirtualFooter) _ftrTmp: VirtualFooter; @ContentChild(VirtualFooter) _ftrTmp: VirtualFooter;
/** /**
* @input {array} The data that builds the templates within the virtual scroll. * @input {array} The data that builds the templates within the virtual scroll.
* This is the same data that you'd pass to `*ngFor`. It's important to note * This is the same data that you'd pass to `*ngFor`. It's important to note
@ -345,7 +344,8 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
* and what data to give to the header template. The function must return * and what data to give to the header template. The function must return
* `null` if a header cell shouldn't be created. * `null` if a header cell shouldn't be created.
*/ */
@Input() set headerFn(val: Function) { @Input()
set headerFn(val: Function) {
if (isFunction(val)) { if (isFunction(val)) {
this._hdrFn = val.bind((this._ctrl._cmp) || this); this._hdrFn = val.bind((this._ctrl._cmp) || this);
} }
@ -358,7 +358,8 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
* should be used, and what data to give to the footer template. The function * should be used, and what data to give to the footer template. The function
* must return `null` if a footer cell shouldn't be created. * must return `null` if a footer cell shouldn't be created.
*/ */
@Input() set footerFn(val: Function) { @Input()
set footerFn(val: Function) {
if (isFunction(val)) { if (isFunction(val)) {
this._ftrFn = val.bind((this._ctrl._cmp) || this); this._ftrFn = val.bind((this._ctrl._cmp) || this);
} }
@ -369,10 +370,14 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
*/ */
@Input() @Input()
set virtualTrackBy(val: TrackByFn) { set virtualTrackBy(val: TrackByFn) {
if (!isPresent(val)) return; if (isPresent(val)) {
this._virtualTrackBy = val; this._virtualTrackBy = val;
this._updateDiffer(); this._updateDiffer();
}; }
}
get virtualTrackBy(): TrackByFn {
return this._virtualTrackBy;
}
constructor( constructor(
@ -485,9 +490,9 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
return null; return null;
} }
private _updateDiffer(): void { private _updateDiffer() {
if (isBlank(this._differ) && isPresent(this._records)) { if (isBlank(this._differ) && isPresent(this._records)) {
this._differ = this._iterableDiffers.find(this._records).create(this.virtualTrackBy); this._differ = this._iterableDiffers.find(this._records).create(this._virtualTrackBy);
} }
} }