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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -