angular2-step-by-step-06-consuming-real-data-with-http
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.
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, …}
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()})