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

前端 未结 19 2477
时光取名叫无心
时光取名叫无心 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:22

    For Angular versions 5 and above, the updated importing line looks like :

    import { map } from 'rxjs/operators';
    

    OR

    import { map } from 'rxjs/operators';
    

    Also these versions totally supports Pipable Operators so you can easily use .pipe() and .subscribe().

    If you are using Angular version 2, then the following line should work absolutely fine :

    import 'rxjs/add/operator/map';
    

    OR

    import 'rxjs/add/operators/map';
    

    If you still encounter a problem then you must go with :

    import 'rxjs/Rx';
    

    I won't prefer you to use it directly bcoz it boosts the Load time, as it has a large number of operators in it (useful and un-useful ones) which is not a good practice according to the industry norms, so make sure you try using the above mentioned importing lines first, and if that not works then you should go for rxjs/Rx

提交回复
热议问题