-1

im using angular 6 and i cant import operator map, i try import of tow ways:

using import { map } from 'rxjs/operators'; but visual studio code acused this operator is never used, and i give this error:

enter image description here

and if i import like this: import 'rxjs/add/operator/map';

im give error too

enter image description here

enter image description here

how i can import this operator map?

Davi Resio
  • 653
  • 2
  • 11
  • 21
  • ``import {map} from 'rxjs/operators'`` is fine . Don't use ``.map()`` on your http calls directly . use ``.pipe(map(yourfunction))`` – CruelEngine Jul 18 '18 at 16:45
  • Possible duplicate of [Angular 2 beta.17: Property 'map' does not exist on type 'Observable'](https://stackoverflow.com/questions/36947748/angular-2-beta-17-property-map-does-not-exist-on-type-observableresponse) – Amit Chigadani Jul 18 '18 at 17:27

2 Answers2

1

If you use Angular 6, you use RxJs 6. For RxJs 6 You need use map like this:

import { map } from 'rxjs/operators';

return this.http.post('...')
  .pipe(
    map((...) => {...})
  );

read more https://medium.com/@swapnilkls29/rxjs-6-0-migration-37a6f3de0000 or here https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md

Hooter
  • 121
  • 3
1

import it like :-

import { map } from 'rxjs/operators';

and use it like:-

const example = source.pipe(map(val => val + 10)); Or

getValues(): Observable<Value[]> {   
  return this.http.get<Response<Values>>(this.url).pipe(
    map(reponse => reponse.data.values)
  );
};

You are missing .pipe, Hope it helps !

Gourishankar
  • 906
  • 1
  • 7
  • 14