Angular HTTP GET with TypeScript error http.get(…).map is not a function in [null]

前端 未结 19 2441
时光取名叫无心
时光取名叫无心 2020-11-22 03:36

I have a problem with HTTP in Angular.

I just want to GET a JSON list and show it in the view.

Service class

im         


        
19条回答
  •  终归单人心
    2020-11-22 04:20

    The map you using here, is not the .map() in javascript, it's Rxjs map function which working on Observables in Angular...

    So in that case you need to import it if you'd like to use map on the result data...

    map(project: function(value: T, index: number): R, thisArg: any): Observable Applies a given project function to each value emitted by the source Observable, and emits the resulting values as an Observable.

    So simply import it like this:

    import 'rxjs/add/operator/map';
    

提交回复
热议问题