ionChange 使用 ion-select 传递的数据不会作为输入传递给 api - Ionic

Data passed by ionChange using ion-select does not get passed as input to the api - Ionic

大家好,我正在开发这个送餐应用程序,用户在 ion-select 组件中输入一个 Delivery Circle,其中 he/she 停留,然后我触发另一个 api通过在另一个 ion-select 组件(区域或位置 he/she 停留并填充 ion-select 基于交付周期 selected.

在这里我可以传递外卖圈的价值,我安慰了价值和它的罚款。但是当我尝试将 id 作为数据传递给下一个 api 它变成空白...

这是我的 html 文件

<ion-content padding class="bgpage">
<div class = "col-md-6">
<ion-item>
  <ion-label>Delivery Circle</ion-label>
  <ion-select [(ngModel)]="data" (ionChange) = "delAreaCircle(del_cir)">
    <ion-option  *ngFor = "let data of circleResponse" [value]="data['del_c_id']">{{data['del_c_name']}}</ion-option>
  </ion-select>
</ion-item>
</div>
<ion-item>
  <ion-label>Area / Near by Locality</ion-label>
  <ion-select [(ngModel)]="area_loc">
    <ion-option value="1">St. cruz</ion-option>
  </ion-select>
</ion-item>
</ion-content>

这是我的 .ts 文件函数。

delCircle(){
let circleUrl = 'http://url/folder/filename.php';
let circleData: Observable<any> = this.http.get(circleUrl);
circleData.subscribe( data => { this.circleResponse = data.json();
this.circleResponse = this.circleResponse; 
console.log(this.circleResponse);

});
}

delAreaCircle(id){
let headers = new Headers();
headers.append('Content-Type', 'application/json');

console.log("Inside Location Cordinates",id)
this.del_id = id;
let options = new RequestOptions({ headers: headers });
let circlePassData = {"del_c_id":this.del_id}
console.log("dataPassed",this.circlePassData);
this.http.post('http://url/folder/filename.php', circlePassData , options)
.subscribe(data => {this.circlePassDataFetch = data.json();

console.log("dataReached",this.circlePassDataFetch);

});  
}

将 (ionChange) 函数中的参数更改为 $event。这会将所选选项的值传递给您的函数。

<ion-content padding class="bgpage">
<div class = "col-md-6">
<ion-item>
  <ion-label>Delivery Circle</ion-label>
  <ion-select [(ngModel)]="data" (ionChange) = "delAreaCircle($event)">
    <ion-option  *ngFor = "let data of circleResponse" [value]="data['del_c_id']">{{data['del_c_name']}}</ion-option>
  </ion-select>
</ion-item>
</div>
<ion-item>
  <ion-label>Area / Near by Locality</ion-label>
  <ion-select [(ngModel)]="area_loc">
    <ion-option value="1">St. cruz</ion-option>
  </ion-select>
</ion-item>
</ion-content>