A
A
Alexander Belov2017-02-01 23:51:23
JavaScript
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';

@Injectable()
export class CartService {
  constructor(private http: Http){ }
  
  getCartItems() {
    return this.http.get('./app/cart/cart.json')
    .map(
      (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):
1afe8a81cf254c4e9f961b7ec93bd81c.png
I decided to play it safe and do everything according to the tutorial like here:
https://www.youtube.com/watch?v=IOp9OmNdHy4
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)
A
Anton, 2017-02-02
@sHinE

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