我正在尝试在我的服务中获得http响应:
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()
);
}
}
但控制台显示EXCEPTION:响应状态:找不到404 404
我的文件树( cart.json 文件位于购物车文件夹根目录中):
发现了类似的问题,但没有答案对我有用。
UPD 将 cart.json 文件移至公开文件夹,将路径更改为缩短的文件解决了这个问题。
return this.http.get('../cart.json')
答案 0 :(得分:1)
您正在尝试从PATH中获取某些内容,而不是URL。您需要在公共文件夹中访问它。