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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -