大家好,我正在开发这个食品配送应用程序,用户在离子选择组件中输入了一个配送圈,他/她停留在那里,然后我通过获取配送圈的值来触发另一个api(例如1 ,2,3 ... etc)放置在另一个离子选择组件中,该组件是他/她留下的区域或位置,并根据所选的传送圈填充离子选择。
在这里,我能够传递交货圈的价值,并且我已经控制了交货价值及其罚款。但是当我尝试将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);
});
}
答案 0 :(得分:0)
将(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>