【发布时间】:2019-01-19 03:36:35
【问题描述】:
在我的 ionic 应用程序中,我尝试将从 php api 返回的数组传递到另一个页面,但它没有传递任何值
在 user.html 页面中,我有一个按钮,当单击时将值传递到下一页
<button ion-button icon-only (click)="goToResult()">
<ion-icon ios="ios-log-out" md="md-log-out" class="user"></ion-icon> Next
</button>
userHome.ts
ngOnInit(){
this.phone = this.navParams.get('phone');
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let options = new RequestOptions({ headers: headers });
let data = {
phone: this.phone
};
let loader = this.loading.create({
content: 'Loading Page Contents',
});
loader.present().then(() => {
this.http.post('http://mypro.com/eApi/retrieve.php',data, options)
.map(res => res.json())
.subscribe(res => {
loader.dismiss()
this.items=res.server_response;
console.log(this.items);
});
});
//this.navCtrl.push(PostPage, data);
}
在同一页面上,这是我尝试传递值的推送导航
goToResult(){
console.log(this.items);
this.navCtrl.push(PostPage,
this.postList = this.items
)
}
在 post.ts 中,我将它添加到了构造函数中
this.navParams.get(this.postList);
然后在我的 post.html
<ion-title *ngFor="let post of postList">{{post.Name}}
</ion-title>
请问,如何将 api 的返回值传递到另一个页面?
谢谢。
【问题讨论】:
标签: php arrays api ionic-framework ionic2