* ngFor中的索引不起作用

时间:2018-08-09 06:46:22

标签: angular ionic2 ionic3

我有这个Ionic 3代码,其中有一个* ngFor循环,但是当我每次尝试打印循环的索引时都尝试打印0;

<ion-list-header *ngFor="let child of item.value[item.key]; let i = index" no-padding>

  <ion-item *ngIf="!child.children" ion-item detail-none class="child-item" text-wrap>
    <h2> 
      <ion-icon aria-label="bulb" 
                class="icon-pad icon icon-md icon-md-orange ion-md-bulb item-icon" 
                color="orange" 
                name="bulb" 
                ng-reflect-name="bulb" 
                role="img" 
                ng-reflect-color="orange"></ion-icon>   
      {{ child['layoutName'] }}
    </h2>
    <h2 *ngIf="statusArray[i]">on {{i}}</h2>
    <button ion-button item-right color="secondary" (click)='on(child,1)'>on</button>
    <button ion-button item-right color="danger" (click)='on(child,0)' >off</button>
  </ion-item>
</ion-list-header>

1 个答案:

答案 0 :(得分:-1)

执行以下调试:

let colorRed: UIColor? = timeLabel.textColor
timeLabel.layer.shadowColor = colorRed?.cgColor
timeLabel.layer.shadowRadius = 4.0
timeLabel.layer.shadowOpacity = 0.9
timeLabel.layer.shadowOffset = CGSize.zero
timeLabel.layer.masksToBounds = false

我认为<ion-list-header ngFor="let child of item.value[item.key]; let i = index" no-padding> {{i}} {{item.value[item.key] | json}} 只有1个元素。