How to get data from json file in angularjs 2 -


i new angularjs2. have retrieve data json file array. can use json data in components.thanks helping me.

first of need keep json file in src/assets folder , read there http

getfromfile(){   debugger;   return this.http.get("./assets/data.json")     .map((response: response) =>response.json())     .catch(this._errorhandler); } _errorhandler(error:response){   console.log(error);   return observable.throw(error || "internal server error"); } 

you need import these:

  import { http, response } '@angular/http';   import { observable } 'rxjs/observable';   import 'rxjs/add/operator/map';   import 'rxjs/add/operator/catch';   import 'rxjs/add/observable/throw'; 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -