Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 Not Found: Angular 2 can't talk to Spring Rest API

I followed Angular 2's Tour of Hero tutorial with in memory database. Then I created a Spring backend to supply data and want to integrate Angular2 with Spring's Rest API.

In Tour of Hero I only changed one line of code in hero.service.ts:

/* private heroesUrl = 'app/heroes'; */
private heroesUrl = 'http://localhost:8080/api/hero/all';

The link I changed to is the the Spring service endpoint, if I type the link in browser, it returns JSON data: [{"id":1,"name":"test"}].

However, I am getting error in Tour of Hero:

EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null

It looks like the spring endpoint of localhost:8080 is not found by Angular application running on localhost:3000. What could be the issue?

like image 556
zhileiw Avatar asked Oct 17 '22 21:10

zhileiw


1 Answers

This was asked a while ago, but probably someone finds it useful.

Delete the following dependency from your package.json:

"angular-in-memory-web-api": "~0.2.4",

Remove it from node_modules directory, delete all InMemoryWebApiModule and InMemoryWebApiModule and InMemoryDataService-related code.

like image 74
mp_loki Avatar answered Oct 21 '22 08:10

mp_loki