Reputation: 3678
I am using this api's for my demo app (https://restcountries.eu/)
API url is this https://restcountries.eu/rest/v2/all
But I am not able to fetch data from service in angular
here is my code https://stackblitz.com/edit/angular-3jpqrc?file=src%2Fapp%2Fapp.component.ts
constructor(private dataservice : DataService){
this.dataservice.fetchDataThroughPromise().subscribe(()=>{
console.log('s')
})
}
service code
fetchDataThroughPromise(){
return this.http.get('https://restcountries.eu/rest/v2/all',
{
headers :new HttpHeaders({
'content-type': 'application/json'
})
});
}
see error when created project using angular cli
Upvotes: 0
Views: 4168
Reputation: 6821
Just remove:
headers :new HttpHeaders({
'content-type': 'application/json'
})
Final code:
fetchDataThroughPromise() {
return this.http.get('https://restcountries.eu/rest/v2/all')
}
Upvotes: 1