Can't read property 'name' of undefined


#1

Haiii. I am the new one to ionic as well as angular. For practice, I am developing an ionic3 app. My app contains a service page “countries.service.ts” which reads countries details form the URL using HTTP. And my home page get the data from the “CountriesService”. But i am getting the error “Can’t read property ‘name’ of undefined”…
In home.html I am trying to read the values like this.:

{{countryObj.name}}

{{countryObj.capital}}

home.ts
ngOnInit(){
this.countriesService.getCountryDetail().subscribe(res => this.countryObj= res.json()[0]);
}
coountries.service.ts
public getCountryDetail(){
let url:string=‘https://restcountries.eu/rest/v2/name/india?fullText=true’;
return this.http.get(url);
}
Thanks in advance…


#2

can you please describe?


#3

Thanks for reply… My countries.service.ts service should get json data of different countries from the url mentioned above. My home.ts file should read the data returned by the**countries.service.ts**