2017-03-02 74 views
0

有誰知道如何重置「離子選擇」的「離子選項」值。我有兩個離子選擇控件,我希望我的第一個離子選擇(selectedPLocation)更改ionChange上的第二個離子選擇(selectedLocation)的值。我能夠通過設置空刪除選中,但我無法更改selectedLocation的值。有誰知道如何重置我的離子選項的價值?重置(ionChange)上的離子選項值 - 離子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> 

打字稿:

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'設置了這些值,但是你並沒有根據任何東西來聲明你希望它們改變到什麼...... locations數組的另一個屬性? – 2017-03-03 19:18:24

+0

我忘了發佈我的手稿代碼來綁定我的數據抱歉。無論如何,我設法解決我自己的錯誤非常感謝。 –

回答

0

我解決我自己的錯誤,這是由於我的打字稿碼打電話給我的web服務API(的getLocation)。

上打字稿代碼:

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); 
      }); 
    }); 
}