I am trying to integrate a masonry grid with infinite scrolling in an angular 4 application.
I am using for masonry the following library masonry.desandro.com and for infinite scrolling: ngx-infinite-scroll
I am having issues when scrolling, the items are being overlapped. I do not know if i am not initializing it properly. I appreciate any help even it implies to use other libraries that work with angular 4.
My code looks like this:
Html:
<div class="search-results" infinite-scroll [infiniteScrollDistance]="2"
[infiniteScrollThrottle]="10" (scrolled)="onScrollDown()"
[scrollWindow]="true">
<div class="grid">
<div class="grid-item grid-item--height{{i}}" *ngFor="let i of array">
{{i}}
</div>
</div>
My component:
export class HomeComponent implements OnInit {
ngOnInit() {
jQuery(document).ready(function () {
jQuery('.grid').masonry({
// options
itemSelector: '.grid-item',
columnWidth: 200
});
});
}
array = [];
sum = 20;
modalIsOpen = '';
constructor() {
for (let i = 0; i < this.sum; ++i) {
this.array.push(i);
}
}
onScrollDown() {
console.log('scrolled!!');
// add another 20 items
const start = this.sum;
this.sum += 20;
for (let i = start; i < this.sum; ++i) {
this.array.push(i);
}
}
}