Error: Property 'map' does not exist on type 'Observable'

别来无恙 提交于 2020-01-11 13:36:11

问题


After I updated angular/cli, I got an error:

error TS2339: Property 'map' does not exist on type 'Observable<Response>'

I tried every possible solution from Property 'map' does not exist on type 'Observable<Response>'

but still the error exists.


回答1:


Its easy to post an answer when you provide your code instead of a screenshot. Anyhow, you have to pipe it:

getUsers() {
    return this._http.get(this.baseUrl+'/show-users', this.options)
                     .pipe(
                          map((response:Response)=>response.json())
                      );

Remember to import map like this:

import { map } from 'rxjs/operators';



回答2:


For the latest Version of rxjs we need to install npm install rxjs-compat from terminal then declare

import 'rxjs/add/operator/map';




回答3:


You can find a solution by using pipe. Here are the steps...

First import map

import {map} from 'rxjs/operators';

Modify your getuser() and other all functions by using pipe

getUser(){
 this._http.get(this.baseUrl+'/show-users', this.options).pipe(map((response:Response)=>response.json()));                
}


来源:https://stackoverflow.com/questions/50503366/error-property-map-does-not-exist-on-type-observable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!