I am trying to fetch data in my first ionic application from server but getting an error Cannot read Property attaching my code snippet. Here is my code:
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)});
}
)
Screenshot of Output:
I've taken the data like this.I hope that solves the problem
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;
});