javascript - Angular4: how do access local json? -
in angular2 have folder /data/ , json file there , access @ localhost:4200/data/something.json.
this no longer possible in angular4.
any ideea how work?
you can use 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
local json file.
see here also
also see changlog of angular-cli path
Comments
Post a Comment