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

Passing return values from php api array to another page

在我的离子应用程序中,我尝试将数组 returned 从 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 中的 return 值传递到另一个页面?

谢谢。

因此,如果您查看 ionic doc 示例,您会发现您需要使用 json 对象传递数据并使用其密钥检索数据,请尝试以下方法:

在你的第一个组件中:

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

在接收组件构造函数中;

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

如果仍然遇到问题,请分享完整代码,但这应该很容易解决;)

你可以这样做

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

在post.ts中,可以通过

获取值
this.navParams.get('postList');