ngx-ui-scroll
Version:
Infinite/virtual scroll for Angular
56 lines • 1.85 kB
JavaScript
import { Component, ElementRef, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { Workflow } from './vscroll';
import consumer from './ui-scroll.version';
export class UiScrollComponent {
constructor(changeDetector, elementRef) {
this.changeDetector = changeDetector;
this.elementRef = elementRef;
// the only template variable
this.items = [];
}
ngOnInit() {
this.workflow = new Workflow({
consumer,
element: this.elementRef.nativeElement,
datasource: this.datasource,
run: items => {
if (!items.length && !this.items.length) {
return;
}
this.items = items;
this.changeDetector.detectChanges();
}
});
}
ngOnDestroy() {
this.workflow.dispose();
}
}
UiScrollComponent.decorators = [
{ type: Component, args: [{
selector: '[ui-scroll]',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div data-padding-backward></div>
<div
*ngFor="let item of items"
[attr.data-sid]="item.$index"
[style.position]="item.invisible ? 'fixed' : null"
[style.left]="item.invisible ? '-99999px' : null">
<ng-template
[ngTemplateOutlet]="template"
[ngTemplateOutletContext]="{
$implicit: item.data,
index: item.$index,
odd: item.$index % 2,
even: !(item.$index % 2)
}"></ng-template>
</div>
<div data-padding-forward></div>`
},] }
];
UiScrollComponent.ctorParameters = () => [
{ type: ChangeDetectorRef },
{ type: ElementRef }
];
//# sourceMappingURL=ui-scroll.component.js.map