Reputation: 567
I can't get JSON local file Angular HTTP service. I have these codes:
import {Injectable} from '@angular/core';
import {Http, Response} from "@angular/http";
import 'rxjs/add/operator/map'
@Injectable()
export class ApiService {
constructor(private http:Http) {
}
private coinsUrl:string = 'app/data/coins.json';
getMines() {
return this.http.get(this.coinsUrl).subscribe(
(res:Response)=> {
const sss = res.json();
console.log('sss', sss);
}
);
}
}
Upvotes: -2
Views: 2642
Reputation: 8928
Since you are using angular-cli that file location will not be available to you at runtime (either using ng serve
or a production build). Put the file in the assets folder and then you can load /assets/coins.json
.
Upvotes: 3