使用离子选择选项,如果用户选择“其他”,则无法获取该值

时间:2019-09-25 07:46:08

标签: angular ionic4

我创建了一个离子选择选项,如果用户选择“其他”,我将显示一个* ngIf,其中显示一个离子输入,以允许用户精确调整其他响应。

我正在尝试保存用户的结果。如果他选择了正常响应,则可以使用ngModel起作用,但对于“其他”响应,我将无法获得答案。

html:

  <ion-item>
    <ion-label>Question :</ion-label>
      <ion-select [(ngModel)]="userType">
        <ion-select-option *ngFor="let rep of Response1" [value]="rep.value" [innerHTML]="rep.value">
        </ion-select-option>
      </ion-select>
  </ion-item>

  <ion-item *ngIf="userType == 'otherOptionValue'">
    <ion-label>Other : </ion-label>
      <ion-input  type="text">
      </ion-input>
  </ion-item>

  <ion-button (click)='onSave()'>
    Save
  </ion-button>

.ts

  Response1 = [
   {value: 'test'},
   {value: 'otherOptionValue'}
  ];

  userType;

  onSave() {
    console.log(this.userType);
  }

因此,当我选择“测试”时,我会进行console.log测试,但是如果我选择“ otherOptionValue”,我的console.log也将是“ otherOptionValue”,但是我想console.log用户的输入值。

0 个答案:

没有答案