当数据包含在数组中时,如何检查离子选择复选框值?

问题描述 投票:0回答:1

如何在从服务器获取数据后加载页面时检查选项?

  <ion-select [(ngModel)]="interests" multiple="true" (ionChange)="addInterests(interests)">
    <ion-option>Automobile</ion-option>
    <ion-option>Cellphones</ion-option>
    <ion-option>Toys</ion-option>
  </ion-select>
javascript angular ionic-framework
1个回答
0
投票

所以在你的打字稿文件中你会有这样的东西:

private interests: Array<string>;
private interestReceivedFromServer: string;

在您的HTML中,您可以这样做:

      <ion-select multiple="true">
        <ion-option *ngFor="let interest of interests" value="{{interest}}" [selected]="interest == interestReceivedFromServer">
          {{ interest }}
        </ion-option>
      </ion-select>

这样会很好。

© www.soinside.com 2019 - 2024. All rights reserved.