I have been attempting to reproduce the ngPrime datatable demo from this Github repository. Currently, I am working with the most recent version of Angular (4) and using angular-cli in development mode. Placing a JSON file into my app folder where the service is located did not solve the issue for me. Despite trying different path configurations, I am still encountering a persistent 404 error.
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Car} from './car';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class CarService {
constructor(private http: Http) {}
getCarsSmall() {
return this.http.get('./cars-small.json')
.toPromise()
.then(res => <Car[]> res.json().data)
.then(data => { return data; });
}
}
The code snippet above originates from their website. In order to make it work, I had to import rxjs toPromise and modify the angular core package definition accordingly.
import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Car} from '../domain/car';
@Injectable()
export class CarService {
constructor(private http: Http) {}
getCarsSmall() {
return this.http.get('/showcase/resources/data/cars-small.json')
.toPromise()
.then(res => <Car[]> res.json().data)
.then(data => { return data; });
}
}
The resolution came when I used the full path as shown below:
return this.http.get('/src/app/cars-small.json')