I am trying to fetch data from my localhost as like this:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class SearchServiceService {
apiRoot:string = 'https://itunes.apple.com/search';
results:Object[];
loading:boolean;
constructor(private http:HttpClient) {
this.results = [];
this.loading = false;
}
search(term:string){
let promise = new Promise((resolve, reject) => {
let apiURL = `${this.apiRoot}?term=${term}&media=music&limit=20`;
this.http.get(apiURL).toPromise().then(res => {
// console.log( res.json() );
resolve();
}, function(error){
console.log('error is', error);
})
});
return promise;
}
}
I am using Chrome
browser. to prevent the CORS
issue i use this extension:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en-US
But still getting the error as :
Failed to load https://itunes.apple.com/search?term=Moo&media=music&limit=20: The 'Access-Control-Allow-Origin' header contains multiple values 'http://evil.com/, *', but only one is allowed. Origin 'http://localhost:4200' is therefore not allowed access.
zone.js:2969 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://itunes.apple.com/search?term=Moo&media=music&limit=20 with MIME type text/javascript. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Not getting the data. what are the changes is I require to do here? anyone help me?