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

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -