I'm encountering an issue while attempting to load dummy JSON data from a file using angular2 http.get method. It appears that the method is unable to retrieve the data, consistently returning a 404 status code for resource not available. Below is the code snippet I am using:
const obs: Observable<any> = this.http.get('http://localhost:4200/assets/mock-json/cashback.json')
.map((res: Response) => {
console.log('***********',res.json());
res.json(); })
.do((res) => this.loadedCB = res);
if (this.loadedCB) {
return Observable.of(this.loadedCB);
}
Interestingly, when I manually enter the URL http://localhost:4200/assets/mock-json/cashback.json in my browser, it successfully retrieves the data. It's puzzling why it doesn't work with http.get().