Angular: 9.0.4: Properti 'peta' tidak ada pada tipe 'Dapat Diamati‹Respon›' [duplikat]

Saya meminta Anda untuk pengertian, saya mencoba banyak sebelum bertanya ...

CLI Sudut: 9.0.4 Node: 12.16.1 OS: win32 x64

    import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { User } from './user';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';


@Injectable()
export class UserService{

    constructor(private _httpService: Http){}

    getAllUsers(): Observable<User[]>{
        return this._httpService.get("http://localhost:7777/webapp/user")
                .map((response: Response) => response.json())
                .catch(this.handleError);
    }

    private handleError(error: Response){
        return Observable.throw(error);
    }

}

Properti 'peta' tidak ada pada tipe 'Dapat Diamati'.ts(2339)


person William Manley    schedule 02.03.2020    source sumber
comment
Coba impor peta rxjs import { map } dari 'rxjs/operator';   -  person Vicky Kumar    schedule 02.03.2020
comment
Apakah ini menjawab pertanyaan Anda? Peningkatan sudut 5 hingga 6: Properti 'peta' tidak ada pada tipe Observable   -  person kunwar97    schedule 02.03.2020


Jawaban (2)


Coba impor peta rxjs dengan cara ini

import { map } dari 'rxjs/operators' Meskipun ada import 'rxjs/add/operator/map';

import { map } from 'rxjs/operators'

getUser(){
this._httpService.get(url)
.pipe(map(r => { console.log(r); return r.json()}))
.subscribe(resp => {

 console.log(resp);
 });
 }

Ini contoh yang berfungsi

person Vicky Kumar    schedule 02.03.2020

import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { User } from './user';
import { map } from 'rxjs/operators'


@Injectable()
export class UserService{

    constructor(private _httpService: Http){}

    getUsers(){
    return this._httpService.get("http://localhost:7777/webapp/user")
    .pipe(map((response: Response) => response.json())
    .subscribe((response: Response) => {
      console.log(response)
    }));
}

    private handleError(error: Response){
        return Observable.throw(error);
    }

}

Properti 'berlangganan' tidak ada pada tipe 'OperatorFunction'.ts(2339)

person William Manley    schedule 02.03.2020