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.

图片转代码服务由CSDN问答提供 功能建议

在我的离子应用程序中,我尝试将从php api返回的数组传递到另一个页面,但它没有传递任何值< / p>

在user.html页面中,我有一个按钮,当点击将值传递到下一页

 &lt; button ion-button icon  -only(click)=“goToResult()”&gt; 
&lt; ion-icon ios =“ios-log-out”md =“md-log-out”class =“user”&gt;&lt; / ion- 图标&GT; 接着
&LT; /按钮&GT; 
   
 
 

<强> 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()。然后 (()=&gt; {
 
this.http.post('http://mypro.com/eApi/retrieve.php',data,options)
 
.map(res =&gt; res.json  ())
 
 .subscribe(res =&gt; {
 
 loader.dismiss()
 
 this.items = res.server_response; 
 
 console.log(this.items); \  n 
}); 
 
}); 
 //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

 &lt; ion-title * ngFor =“发布信息 postList“&gt; {{post.Name}} 
&lt; / ion-title&gt; 
   
 
 

请问,如何从api传递返回值 到另一页?

谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题