Alexander Belov2017-02-01 23:51:23
Alexander Belov, 2017-02-01 23:51:23

Angular2 doesn't see json on http request, wtf?

Understanding Angular2 service:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';

import 'rxjs/add/operator/map';

export class CartService {
  constructor(private http: Http){ }
  getCartItems() {
    return this.http.get('./app/cart/cart.json')
      (res) => res.json()

The console gives an error EXCEPTION: Response with status: 404 Not Found for URL: localhost:8080/app/cart/cart.json Changed
file paths in various variations from abbreviated to full, etc.
Tree (cart.json is in the cart folder without additional attachments):
I decided to play it safe and do everything according to the tutorial like here:
Still the same error, xs, how to solve it .
Correct answer: Copy the file to the public folder and write the short path
return this.http.get('../cart.json')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Anton, 2017-02-02

Were the paths from where the rest of the files are loaded checked (and compared with the path to cart.json)?
Did you check all the letters in the way in English?
Is the file in lower case named like in the url?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question