Reputation: 1834
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')
Upvotes: 1
Views: 2169
Reputation: 5740
You're trying to require something from a PATH, rather then a URL. You need to make it accessible in your public folder.
Upvotes: 1