【发布时间】:2017-06-05 20:57:33
【问题描述】:
我的服务中有此代码
import {Injectable} from '@angular/core';
import {Http, Headers, RequestOptions} from '@angular/http';
import 'rxjs/add/operator/map';
import {Client} from "../clients/client";
import {Observable} from "rxjs/Observable";
@Injectable()
export class ClientsService {
private clientUrl = './client.json';
private headers = new Headers({ 'Accept': 'application/json' });
private options = new RequestOptions({ headers: this.headers });
private client : Client;
constructor(private http:Http) {}
getClient() : Observable<any>{
return this.http.get(this.clientUrl, this.options)
.map(res => res);
}
}
在我的组件中我称之为:
this.client = this.clientsService.getClient()
.subscribe(data => {
console.log(data);
});
但我收到 404 错误
但我在我的服务所在的同一文件夹中有这个 json 文件。
怎么了?
【问题讨论】:
标签: json angular typescript