Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an array of channels. I am using *ngFor for looping the array of channels.

<ng-container *ngFor="let channel of channelList; let i = index">

     // display below code at index 3 and then after every 5th item
      <ng-container *ngIf="i==3">
        <div class="slide pa1" >
          <a class="link bg-center relative" >
            <div class="c-ban relative" style="height: 168px !important;">
              <app-google-ads></app-google-ads>
            </div>
          </a>
        </div>
      </ng-container>
    
  </ng-container> 

Here I have displayed the content at index 3. But how can I display the content after evert fifth element. For instance, the item is displayed at index 3, then I want to display content at index 8 and then at index 13 ... (after every fifth element).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
358 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could do the following. Working out the remainder when you divide by 5 and then - 3 to get the desired offset.

<ng-container *ngIf="(i % 5) - 3 == 0">
    <div class="slide pa1" >
      <a class="link bg-center relative" >
        <div class="c-ban relative" style="height: 168px !important;">
          <app-google-ads></app-google-ads>
        </div>
      </a>
    </div>
  </ng-container>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...