如何在离子2选择中选择第一个选项。所选属性不起作用

时间:2017-03-16 13:09:07

标签: angular ionic-framework ionic2

我正在尝试从<ion-select>中选择第一个值,但它无效。它在第一个(变量)中给出了真实。如果我在循环中打印它。它通常像我猜的那样工作。

  

dashboard.html

<ion-list>
<ion-item *ngIf="locations != null">
  <ion-label>Location</ion-label>
  <ion-select name="locSelect" #newSelect [(ngModel)]="location" (ionChange)="changeStock(location)">
    <ion-option value="{{loc.id}}" *ngFor="let loc of locations let first = first; let last = last; let i = index;" [selected]="first">{{loc.location_name}}</ion-option>
  </ion-select>
</ion-item>

  

dashboard.ts

getLocations(id) {
      this.catService.getLocations(id, this.user.apiToken, this.user.role_id).then(result => {
            this.locations = result;

            if(this.user.role_id == 2) {
                this.getDailyItemLogAdmin(this.firstLocationID, this.user.id);
            }else if(this.user.role_id == 3) {
                this.getDailyItemLogManager(this.firstLocationID, this.user.id);
            }

      })
  }

我从构造函数调用上面的getLocations()函数。

1 个答案:

答案 0 :(得分:1)

dashboard.ts 中,尝试将ngModel变量 <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:7 /nowarn:1659;1699;1701" /> </compilers> </system.codedom> 设置为第一个位置。

location
相关问题