I want ngFor to only return one random entry (using InfiniteScroll), is it possible?

I don't know if this was the best approach, but let me explain what I am doing.

I have a mobile app with ionic and angular. On it I have ngFor which takes data in observable and displays normally. I have set a condition that every 5 entries based on the ngFor index call a new ngFor in another one observable with declarations.

I would like this ad to only return a random entry using PIPE, but since I'm using InfiniteScroll, when it loads more data, it will remix all ads previously loaded.

Is this possible or would this be the best approach?

snippet of template

<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 don't know how I can fix this so as not to rebuild the ads that I have already downloaded.

+3
angular ionic-framework ionic2


source to share


No one has answered this question yet

Check out similar questions:

3
Reading object field from observable using asynchronous pipe
2
How do I return a variable in * ngFor?
1
* ng For iterating over the observable. Filtering onInput should be possible. How?
1
ngFor will not update the list after getting information from Firebase API
1
NgFor wants an array
0
Is it possible to add directives to * ngFor in angular2?
0
The nested ngFor only returns the last element on the inner ngFor
0
Angular / Ionic: ng to return blank
0
Return relative key of Firebase from ngFor loop
0
Generating a random id inside ngFor



All Articles
Loading...
X
Show
Funny
Dev
Pics