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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -