2

my html is simple like this

<ion-list>
 <ion-item *ngFor="let item of editLists,index as i">
      <ion-input [(ngModel)]="editLists[i]"></ion-input>
    </ion-item>
</ion-list>

 <ion-input [(ngModel)]="foo"></ion-input>

it'ok type words when ion-input outside ngFor; but when inside it will lose focus when i type one word how? many thanks

tao wang
  • 93
  • 10

1 Answers1

4

Use trackBy along with ngFor to avoid re rendering input whenever input changes.

component.html

<ion-list>
 <ion-item *ngFor="let item of editLists,index as i;trackBy:trackEditList">
      <ion-input [(ngModel)]="editLists[i]"></ion-input>
    </ion-item>
</ion-list>
</ion-content>

component.ts

trackEditList(index,item){
    return index;
}

Working Example

Chellappan வ
  • 23,645
  • 3
  • 29
  • 60