当从 select 框中 select 编辑特定选项时显示输入字段 - Ionic2

Show input field when specific option is selected from select box - Ionic2

当我 select 选项时,我想显示一个输入文本标签。

html代码

<ion-item >
   <ion-label floating>TIN/GRN NO</ion-label>
   <ion-select [(ngModel)]="num">
     <ion-option *ngFor="let nom of list" value="{{nom.value}}" checked="  {{nom.checked}}" [innerHTML]="nom.label">{{nom.text}}</ion-option>
    </ion-select>
  </ion-item>
  <ion-item *ngIf="num == 'true'">
     <ion-label>Detail</ion-label>
     <ion-input type="text"></ion-input>
  </ion-item>

ts 文件

num = 'true';
 list: Array<{ value: number, text: string, checked: boolean }> = [];

constructor:
        this.list.push({ value: 1, text: 'TIN NO', checked: false  });
        this.list.push({ value: 2, text: 'GRN NO' , checked: false });

由于您正在执行 <ion-select [(ngModel)]="num">,因此 num 属性 将具有值 12(不是真或假)所以在您看来,您需要与这些值进行比较:

  <ion-item *ngIf="num == 1">
     <ion-label>Detail</ion-label>
     <ion-input type="text"></ion-input>
  </ion-item>