I do not know if this would be the best approach, but let me explain what I'm doing.
I have a mobile application with ionic and angular. On it I have a ngFor that takes data in an observable and normally displays. I put a condition that every 5 records, based on the ngFor index, excute a new ngFor in another observable with ads.
I would like this ad ngFor to return only a random record using a PIPE, but as I use an InfiniteScroll whenever it loads more data it remixes all previously loaded ads.
Is it possible or would it be a better approach?
Heres de template snippet
<div *ngFor="let item of produtos | async; let i = index">
<ion-card >
<ion-item>
{{ item.name }}
</ion-item>
</ion-card>
<div *ngIf="( (i % 4 == 0) && ( x > 0 ) )" >
<ion-card >
<ion-item *ngFor="let ads of allads | onerandom" >
<p>{{ ads?.adsCompany }}</p>
</ion-item>
</ion-card>
</div>
</div>
Heres the PIPE
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'onerandom'
})
export class oneRandomObject implements PipeTransform {
transform(values): any {
var myrand = Math.floor(Math.random() * values.length);
var temparray = []
temparray[myrand] = values[myrand];
return temparray;
}
}
I do not know how I can fix it to not remix the ads I've already loaded.