duanji1026 2018-08-12 00:37
浏览 110
已采纳

将返回值从php api数组传递到另一个页面

In my ionic app I tried passing array returned from a php api to another page but it was not passing any values

In user.html page I have the button that when click pass the value to the next page

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

On the same page, this is the push nav I tried passing the values through

goToResult(){
    console.log(this.items);
      this.navCtrl.push(PostPage,
        this.postList = this.items
      )

  }

In post.ts, I added this to the contructor

this.navParams.get(this.postList);

then in my post.html

<ion-title *ngFor="let post of postList">{{post.Name}}
        </ion-title>

Please, how can I pass the return values from the api to another page?

Thanks.

  • 写回答

2条回答 默认 最新

  • douxian9943 2018-08-12 03:57
    关注

    So if you check ionic doc example you will see that you need to pass data using json object and use its key to retrieve data, try this approach:

    In your first component:

       this.navCtrl.push(PostPage,
            { postList: this.items } 
       )
    

    In receiving component constructor;

    this.postList = this.navParams.get(“postList”);
    

    If still struggle please share full code, but this should be easy fix;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R