I am trying to get an http response in my 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('./cart/cart.json')
.map(
(res) => res.json()
);
}
}
But console shows EXCEPTION: Response with status: 404 Not Found for URL
My file tree (the cart.json file is in the cart folder root):
Found similar questions, but no answer worked to me.
UPD Moving the cart.json file into public folder and changing path to a shortened one solved the problem.
return this.http.get('../cart.json')