C.E James
C.E James

Reputation: 335

Error: property map doesn't exist on type 'Observable<Response>'

import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

this part is not working. can you help me to solve this problem?

Upvotes: 0

Views: 3079

Answers (1)

Vikas
Vikas

Reputation: 12036

You are using HttpModule which is deprecated you should use HttpClientModule instead
Regarding the error

property map doesn't exist on type 'Observable'

RxJS v5.5.2+ has moved to Pipeable operators to improve tree shaking and make it easier to create custom operators. now operators need to be combined using the pipe method
Refer This
New Import

import { map} from 'rxjs/operators';

Example

myObservable
  .pipe(map(data => data * 2),)
  .subscribe(...);

Modified code

    getShoppingItems() { return this.http.get('localhost:3000/api/items')
    .pipe(map(res => res.json())); } }

Upvotes: 3

Related Questions