Angular 2 *ngFor - Conditional wrapper element. Like using bootstrap row with three columns inside, then add a new row

后端 未结 5 1302
挽巷
挽巷 2021-01-15 12:00

I am using *ngFor and it has me perplexed. I am trying to use UIkit but it would be applicable to Bootstrap also.

5条回答
  •  死守一世寂寞
    2021-01-15 12:13

    As the other answer proposed, storing the index with something like *ngFor="let device of devices ; let i = index" will let you keep track of the index in the collection you're iterating over.

    Then, as far as I understand you need correctly, you want to conditionally apply a class to elements, namely the first and every third. If you actually want a series like T,F,F,T,F,F,T,F,F,T,... then you can use i % 3 === 0 to produce it and apply a class conditionally with something like

    This will let you conditionally add a class to the first and every third element afterwards.

    If instead you want to have different html based on the index, then you have to use ngIf branching and have two html snippets to handle the two cases. Something in the lines of:

    first case
    second case

提交回复
热议问题