Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 离子3-离子选择无法查看选择选项的值_Html_Ionic3_Html Select_Angular6_Ion Select - Fatal编程技术网

Html 离子3-离子选择无法查看选择选项的值

Html 离子3-离子选择无法查看选择选项的值,html,ionic3,html-select,angular6,ion-select,Html,Ionic3,Html Select,Angular6,Ion Select,我正在处理选择选项菜单。我无法在下拉选择中看到值。我不知道我做错了什么。请检查一下下面的代码 1。HTML <ion-item id="fontBar" *ngIf="isAddTextSelected"> <ion-label>Gender</ion-label> <ion-select [(ngModel)]="gender"> <ion-option *ngFor="let employee

我正在处理选择选项菜单。我无法在下拉选择中看到值。我不知道我做错了什么。请检查一下下面的代码

1。HTML

<ion-item id="fontBar" *ngIf="isAddTextSelected">
      <ion-label>Gender</ion-label>
      <ion-select [(ngModel)]="gender">
          <ion-option *ngFor="let employee of employees" [value]="employee"></ion-option>
      </ion-select>
    </ion-item>
我在构造函数中为employees变量添加了值

注意-:我已经在app.module.ts中导入了下面的内容,甚至添加到了所需的ts文件中。

3。输出-


您必须给选项一个内部值,如下所示:

<ion-option [value]="group.id">
  {{ group.name }}
</ion-option>

{{group.name}

选择组件接受子离子选项组件。如果ion选项未指定值属性,则它将使用其文本作为值。 因此,您可以通过两种方式解决此问题:

1.使用价值:

<ion-select [(ngModel)]="gender">
 <ion-option *ngFor="let employee of employees" [value]="employee">
    {{employee}}
 </ion-option>
</ion-select>

{{employee}}
2.无价值:

<ion-select [(ngModel)]="gender">
 <ion-option *ngFor="let employee of employees">
    {{employee}}
 </ion-option>
</ion-select>

{{employee}}
参考:

<ion-select [(ngModel)]="gender">
 <ion-option *ngFor="let employee of employees" [value]="employee">
    {{employee}}
 </ion-option>
</ion-select>
<ion-select [(ngModel)]="gender">
 <ion-option *ngFor="let employee of employees">
    {{employee}}
 </ion-option>
</ion-select>