เชิงมุม: 9.0.4: คุณสมบัติ 'แผนที่' ไม่มีอยู่ในประเภท 'สังเกตได้‹การตอบสนอง›' [ซ้ำกัน]

ผมขอให้เข้าใจผมพยายามมามากก่อนถาม...

CLI เชิงมุม: 9.0.4 โหนด: 12.16.1 ระบบปฏิบัติการ: 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);
    }

}

ไม่มีคุณสมบัติ 'แผนที่' ในประเภท 'Observable'.ts (2339)


person William Manley    schedule 02.03.2020    source แหล่งที่มา
comment
ลองนำเข้าแผนที่ rxjs import { map } จาก 'rxjs/operators';   -  person Vicky Kumar    schedule 02.03.2020
comment
สิ่งนี้ตอบคำถามของคุณหรือไม่? อัปเกรด Angular 5 ถึง 6: ไม่มีคุณสมบัติ 'แผนที่' ในประเภทที่สังเกตได้   -  person kunwar97    schedule 02.03.2020


คำตอบ (2)


ลองนำเข้าแผนที่ rxjs ด้วยวิธีนี้

นำเข้า { map } จาก 'rxjs/operators' แม้จะมีการนำเข้า '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);
 });
 }

นี่คือตัวอย่างการทำงาน

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);
    }

}

ไม่มีคุณสมบัติ 'สมัครสมาชิก' ในประเภท 'OperatorFunction'.ts (2339)

person William Manley    schedule 02.03.2020