Error: Property 'map' does not exist on ty

2020-05-04 23:12发布

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

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

enter image description here

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

but still the error exists.

3条回答
家丑人穷心不美
2楼-- · 2020-05-04 23:32

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

import 'rxjs/add/operator/map';

查看更多
Anthone
3楼-- · 2020-05-04 23:43

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';
查看更多
看我几分像从前
4楼-- · 2020-05-04 23:44

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()));                
}
查看更多
登录 后发表回答