首页 > 解决方案 > 如何在 ion-select-option 中使用循环至少 100 个项目并在 .ts 文件中绑定

问题描述

我想使用任何循环在离子选择项中使用至少 18 到 100 岁的年龄列表。并在 .ts 文件中进行数据绑定

<ion-item class="my-item5" > 
    <ion-icon name='podium' item-right color="gray"></ion-icon>
    <ion-label class="gen-col">Select age</ion-label>
    <ion-select value="age" okText="Ok" cancelText="Cancel">                                       
        <ion-select-option value="18">18</ion-select-option>
        <ion-select-option value="19">19</ion-select-option>
        <ion-select-option value="20">20</ion-select-option>
        <ion-select-option value="21">21</ion-select-option>
    </ion-select>
</ion-item>

标签: angularionic4

解决方案


我在 .htmnl 中找到了上述问题的解决方案

ion-select-option *ngFor="let age of ageList">{{age}}</ion-select-option>  

在.ts

ageList:Array<any> = [];
this.ageList = Array.from({length:90},(v,k)=>k+18); 

推荐阅读