В моей машинописи я получаю сообщение об ошибке:
Property 'results' does not exist on type Object
;
Но код работает отлично. Мне нужно знать, что я здесь пропустил. кто-нибудь мне помочь?
Ошибка:
вот мой код (TS):
import { Injectable } from '@angular/core';
import { Response, RequestOptions, Headers } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
interface CountryDetails {
countryLongName: string;
countryShortName: string;
}
@Injectable()
export class ServerService {
// latlng=40.714224,-73.961452&sensor=false
googleApi:string = "http://maps.googleapis.com/maps/api/geocode/json?latlng=";
postParam: any;
options: any;
countryDetails:CountryDetails;
constructor(private http:HttpClient) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.postParam = {
"clientId": "RETAIL",
"spvParam": {
"productCode": "PDO",
"consigneeCountry": "MY",
"salesOrgRef": "TH61",
"salesOrgFacilityCode": "THBKK1",
"salesOrgChnl": "eCommerce",
"pickUpAcctRef": "5999999108",
"facilityId": "MYKUL1"
}
}
this.options = new RequestOptions({ headers: headers });
}
public getCountry(lat,lan):Observable<any>{
return this.http.get(this.googleApi+lat+','+lan+'&sensor=false').map( data => {
data.results.map( array => {
let details = array.address_components.find( obj => obj.types.includes("country") );
this.countryDetails.countryLongName = details.long_name;
this.countryDetails.countryShortName = details.short_name;
})
return this.countryDetails;
})
}
}