代码之家  ›  专栏  ›  技术社区  ›  Sahil

如何在离子行中以交替颜色显示离子项目?

  •  5
  • Sahil  · 技术社区  · 7 年前
    <ion-row   *ngFor="let box of Boxes"   >
      <ion-col col-9>
      <ion-item  >
      {{box}}
      </ion-item>
      </ion-col>
      <ion-col col-3>
          <ion-checkbox></ion-checkbox>
      </ion-col>
    
    </ion-row>
    

    如何以其他颜色显示项目?每行项目的备选颜色。?

    3 回复  |  直到 7 年前
        1
  •  12
  •   AddWeb Solution Pvt Ltd    7 年前

    尝试以下操作:

    。html

    <ion-row   *ngFor="let box of Boxes; let i = index;">
        <ion-col col-9>
            <ion-item  [ngClass]="(i % 2 == 0) ? 'odd' : 'even'">
                {{box}}
            </ion-item>
        </ion-col>
        <ion-col col-3>
            <ion-checkbox></ion-checkbox>
        </ion-col>
    </ion-row>
    

    。scss公司

    .odd{
      color: blue;
    }
    .even{
      color: green;
    }
    
        2
  •  1
  •   Utpaul    5 年前

    尝试以下操作:

    。html

    <ion-row   *ngFor="let box of Boxes">
        <ion-col col-9>
            <ion-item  class="custom-bg">
                {{box}}
            </ion-item>
        </ion-col>
        <ion-col col-3>
            <ion-checkbox></ion-checkbox>
        </ion-col>
    </ion-row>
    

    。scss公司

    .row-custom-bg:nth-of-type(even) {
        background: green;
    }
    .row-custom-bg:nth-of-type(odd) {
        background: blue;
    }
    

    我认为这会很有帮助。。

        3
  •  0
  •   Ankit Kapoor    7 年前

    可以使用ngFor的奇偶属性

    <ion-row   *ngFor="let box of Boxes; let odd=odd; let even=even;
    [ngClass]="{ odd: oddStyleClass, even: evenStyleClass }   >
    

    在这里,oddStyleClass和evenStyleClass将定义背景色或您想要应用的任何其他样式