I've finished the angular2 heroies tutorial https://angular.io/docs/ts/latest/tutorial/ and now I'am trying to call a ral REST api that i've made with Node, Postgresql and Express.
The angular2 code calling the API looks like this:
...
export class HeroService{
private heroesUrl = 'http://192.168.4.13:3000/api/boxes'; //URL til api
private headers = new Headers({'Content-Type': 'application/json'});
constructor(private http: Http) {}
getHeroes(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
}
...
The browser console shows:
An error occurred Response {_body: Object, status: 404, ok: false, statusText: "Not Found", headers: Headers…} EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null
And I can see that my API isen't being called. Any ideas to what I'am missing out?
Best regards.
404. If you are also trying to call.json()on theresponsethen it will fail because the content is not JSON. What is the API URL that you are trying to call? How did you define that API at the server side?http://part from the URL? Also, can you open the browser console, select the network tab and refresh the page where you expect this to be called. That might help with understanding the problem better.