我正在尝试从服务器获取第一个离子应用程序中的数据,但是收到错误无法读取属性附加我的代码片段。这是我的代码:
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)});
}
)
输出截图:
答案 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;
});