5

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?

abronan
  • 3,309
  • 4
  • 29
  • 38
zhileiw
  • 51
  • 2
  • Have a look at network tab and see what's the actual url that it hits – Milad Nov 27 '16 at 04:11
  • Hi. Did you ever get to resolve this issue? I experience similar issues, with running Angular 2 and Spring both on the same port or separately. What I get is 404 `'Not Found for URL: '` error. In my case I am not even sure it gets to the server side, because it gives the same error regardless if the server is up or down. – mp_loki Jan 29 '17 at 16:12

1 Answers1

3

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.

mp_loki
  • 1,018
  • 1
  • 10
  • 21