2017-03-02 14 views
0

"ion-select"の "ion-option"値をリセットする方法を知っている人はいませんか?私は2つのイオン選択コントロールを持っています。私は第1のイオン選択(selectedPLocation)を使って、第2のイオン選択(selectedLocation)の値をionChangeに変更します。 nullを設定して選択項目を削除することはできますが、selectedLocationの値を変更することはできません。誰も私のイオンオプションの値をリセットする方法を知っていますか?(ionChange) - ionicのイオンオプション値をリセットする2

私は現在VS2015のIDEを使用しています。

HTML:

<ion-list> 
    <ion-item> 
      <ion-label>Parent Location</ion-label> 
      <ion-select [(ngModel)]="selectedPLocation" (ionChange)="loadLocation()"> 
       <ion-option *ngFor="let parentLocation of parentLocations; let i=index" [value]="parentLocation.Key">{{parentLocation.Id}}</ion-option> 
      </ion-select> 
    </ion-item> 
    <ion-item> 
      <ion-label>Location</ion-label> 
      <ion-select [(ngModel)]="selectedLocation"> 
       <ion-option id="locationID" *ngFor="let location of locations; let i=index" [value]="location.Key">{{location.Id}}</ion-option> 
      </ion-select> 
    </ion-item> 
</ion-list> 

活字体:私の活字体のコードは私のWebサービスAPI(のgetLocation)に呼び出すために私は自分のエラーを解決し

public loadLocation() { 
let loader = this.loadingCtrl.create({ 
    content: "Please wait..." 
}); 
loader.present(); 

this.selectedLocation = null; //Reset selected value only 
this.locations = null; //Tried this but can't seem to reset the values 

this.locationService.GetLocations(this.global.getApiUrl(), this.selectedSite, this.selectedPLocation).then(data => { 
    loader.dismiss(); 
    this.locations = data; 
}).catch((err) => { 
    loader.dismiss(); 
    let alert = this.alertCtrl.create({ 
     title: 'Error', 
     subTitle: err, 
     buttons: ['OK'] 
    }); 
    alert.present(); 
});} 
+0

あなたがに値を変更したいのですか?あなたはすでに '* ngFor'で値を設定していますが、何に基づいて変更したいのか...州配列の別のプロパティ? –

+0

私のデータをバインドするためにTypescriptコードを投稿するのを忘れてしまいました。とにかく、私は自分自身のエラーを解決するために管理してくれた多くのありがとう。 –

答えて

0

は、それが原因です。

前の活字体コード:

public GetLocations(apiUrl, siteKey, pLocationKey) { 

    return new Promise((resolve, reject) => { 
     this.http.get(apiUrl + "site/" + siteKey + "/location/" + pLocationKey) 
      .map(res => res.json()) 
      .subscribe(data => { 
       this.Locations = data;  //Error Here 
       resolve(this.Locations);; //Error Here 
      }, 
      err => { 
       reject(err); 
      }); 
    }); 
} 

正しい活字体コード:

public GetLocations(apiUrl, siteKey, pLocationKey){ 

    return new Promise((resolve, reject) => { 
     this.http.get(apiUrl + "site/" + siteKey + "/location/" + pLocationKey) 
      .map(res => res.json()) 
      .subscribe(data => { 
       resolve(data);  //Corrected 
      }, 
      err =>{ 
      reject(err); 
      }); 
    }); 
} 
関連する問題