以离子形式获取数据

时间:2017-05-23 11:33:55

标签: javascript php json ionic-framework

我正在尝试从服务器获取第一个离子应用程序中的数据,但是收到错误无法读取属性附加我的代码片段。这是我的代码:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http} from '@angular/http';
import 'rxjs/add/operator/map'

@Component({
 selector: 'page-test',
 templateUrl: 'test.html'
})
export class TestPage {

 posts: any;

constructor (public navCtrl: NavController, public http: Http) {

  this.http.get.('http://localhost/AppApis/salesheader.php').map(res => res.json()).subscribe(response => {

  console.log(response.object.object.object.cardname)});

}
)

输出截图:

1 个答案:

答案 0 :(得分:0)

我已经采用了这样的数据。我希望能解决问题

<强> service.ts

  getdata() {

   var response = this.http.get('http://xxxxxx').map(res => res.json());
      console.log(response);
        return response;

}

<强> test.ts

getdata:any;

  constructor(public navCtrl: NavController, public navParams: NavParams,public service:Service,public http : Http) {}

   this.service.getdata().subscribe(
                    data=>{

                   this.getdata = data;


                    });