I made an api call and get a response as below, shown on console
My Api Provider:
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
@Injectable()
export class RestapiProvider {
apiUrl = 'http://example.com/api/GetItemByCategory?cat_id=1&merchant_id=1&json=true';
constructor(public http: HttpClient) {
//console.log('Hello RestapiProvider Provider');
}
getItembyCategory() {
return new Promise(resolve => {
this.http.get(this.apiUrl).subscribe(data => {
resolve(data);
console.log(data);
}, err => {
console.log(err);
});
});
}
Console.log(data) shows
[object Object]: {code: 1, details: Object, msg: "success..", request: "{"cat_id":"1","merchant_id":"1","json":"true"}"}
I need to parse the json data on 'details: Object'
I tried console.log(data.details)
got error:
Unable to get property 'details' of undefined or null reference
UPDATE
I was trying to use map operator as below
this.http.get(this.apiUrl).map(data => data.json()).subscribe(data => {
resolve(data);
console.log(data);
}
Got another error: property json does not exist on type 'Object'
Please let me know how to make it work on ionic 3.
Regards
console.log(data.details)