清除输入内容下方的输入字段已更改

时间:2019-11-25 12:22:51

标签: angular typescript ionic3

我有以下带有几个输入字段的HTML。根据您要修改的输入字段,我需要清除其余字段,这些字段位于要修改的字段之下。 在Angular中是否有类似nextAll的功能?

<ng-container *ngFor="let requiredItem of modifyOrderAddressViewModel.required; let i = index">

        <ion-item *ngIf="requiredItem.noSelectable">
            <ion-label stacked>{{ requiredItem.title }}</ion-label>
            <ion-input
                (ionBlur)="onChangeStreetNr(requiredItem)"
                (ionFocus)="checkInput()"
                [disabled]="requiredItem.fieldType === ADDRESS_OPTIONS.POSTAL_CODE"
                type="text" 
                maxlength="5"
                [(placeholder)]="requiredItem.placeHolder" 
                [(ngModel)]="requiredItem.value">
            </ion-input>
        </ion-item>
</ng-container>

1 个答案:

答案 0 :(得分:4)

您已经具有ngFor的索引。只需在值更改时使用它

<ng-container *ngFor="let requiredItem of modifyOrderAddressViewModel.required; let i = index">
  <ion-item *ngIf="requiredItem.noSelectable">
      <ion-input [(ngModel)]="requiredItem.value" (ngModelChange)="clearAllFrom(i)">
      </ion-input>
  </ion-item>
</ng-container>

组件:

clearAllFrom(startIndex) {
    for(let i = startIndex + 1, e = modifyOrderAddressViewModel.required.length; i < e; ++i) {
      modifyOrderAddressViewModel.required[i].value = '';
    }
}