typescript - angular 2 http get 404 -
i'm trying replicate ngprime datatable demo https://github.com/primefaces/primeng. i'm using latest version of angular (4), along angular-cli (dev mode). dropped json file app folder, service located. i've tried mess around path, can't figure out. continue 404.
import {injectable} '@angular/core'; import {http, response} '@angular/http'; import {car} './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; }); } }
here src site. did have import rxjs topromise , modify angular core package definition.
import {injectable} 'angular2/core'; import {http, response} 'angular2/http'; import {car} '../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; }); } }
using complete path solved issue:
return this.http.get('/src/app/cars-small.json')
for reason making change worked-
return this.http.get('/src/app/cars-small.json')
i don't understand why had go 2 directories, when file @ same level. tried app/cars-small.json, , didn't work either.
Comments
Post a Comment