Angular 2 HTTP GET 404 Not Found for URL

前端 未结 3 1289
再見小時候
再見小時候 2020-12-08 21:02

I am trying to integrate Angular 2 application with Java Spring Boot backend. For the moment, I place my Angular 2 files under src/main/resources/static (meanin

相关标签:
3条回答
  • 2020-12-08 21:36

    I had a similar issue, after some frustrating researches I solved the 404 error thanks to this. The order of imports matters.
    Hope it helps someone.

    0 讨论(0)
  • 2020-12-08 21:46

    The reason of this error was that I used Angular Tour of Heroes applcation as a basis for mine, and I did not remove the dependency

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

    and InMemoryWebApiModule from app.module.ts. Because of this all requests were intercepted by InMemoryWebApiModule (despite I did not call it directly as described in Tour of Heroes Tutorial), that's why I did not see any XMLHttpRequests in 'Network' tab of the browser debugger.

    After I have removed the dependency from package.json and node_modules directory, it started working normally, however, I had to change the service code to parse Json directly to TypeScript objects like this:

    getLanguages(): Promise<Language[]> {
        return this.http.get(this.langUrl)
            .toPromise()
            .then(response => response.json() as Language[])
            .catch(this.handleError);
    }
    

    This is a newbie mistake, but I hope this post will save a couple of hours of research to someone.

    0 讨论(0)
  • 2020-12-08 21:57

    In Chrome or Firefox you can see the HTTP requests and responses your application executes (just hit F12 and select the Network tab). Since you are saying it is working with your browser or Postman, you can compare both requests and should quickly find the difference.

    0 讨论(0)
提交回复
热议问题