I'm having an issue with my service code. Here is the code snippet:
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);
}
}
In my component, I call the service like this:
this.client = this.clientsService.getClient()
.subscribe(data => {
console.log(data);
});
However, I keep receiving a 404 error.
https://i.sstatic.net/cGldD.png
What's causing the issue? The JSON file is in the same folder as my service.
https://i.sstatic.net/7ktuD.png
Can anyone help me troubleshoot this problem?