In Angular2 you could have a folder /data/ and a json file there and you could access it at localhost:4200/data/something.json.
This is no longer possible in Angular4.
Any ideea how to get it to work?
See Question&Answers more detail:osIn Angular2 you could have a folder /data/ and a json file there and you could access it at localhost:4200/data/something.json.
This is no longer possible in Angular4.
Any ideea how to get it to work?
See Question&Answers more detail:osyou can use this code
@Injectable()
export class AppServices{
constructor(private http: Http) {
var obj;
this.getJSON().subscribe(data => obj=data, error => console.log(error));
}
public getJSON(): Observable<any> {
return this.http.get("./file.json")
.map((res:any) => res.json())
.catch((error:any) => console.log(error));
}
}
here file.json
is your local json file.
see here also
also see the changlog of angular-cli for path