angular2-step-by-step-06-consuming-real-data-with-http icon indicating copy to clipboard operation
angular2-step-by-step-06-consuming-real-data-with-http copied to clipboard

The app worked when using local data. following error when i'm using api.

Open annadiVreddy opened this issue 7 years ago • 1 comments

Failed to load https://swapi.co/api/people: Redirect from 'https://swapi.co/api/people' to 'https://swapi.co/api/people/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

core.es5.js:1020 ERROR Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers, …}

annadiVreddy avatar Nov 09 '17 20:11 annadiVreddy

Hey I fixed this issue by going into src/app/people.service.ts and in the getAll() method adding a / after people. i.e line 25 .get(`${this.baseUrl}/people`, { headers: this.getHeaders()})

becomes

.get(`${this.baseUrl}/people/`, { headers: this.getHeaders()})

C-Lelievre avatar Feb 06 '18 21:02 C-Lelievre