Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:Property 'map' does not exist on type 'Observable<Object>

Tags:

angular

rxjs

In my Angular10 project this comes even though I import 'rxjs/operator/map'; and import { map } from 'rxjs/operators';

Service Code is

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map, filter, scan } from 'rxjs/operators';
import 'rxjs/add/operator/map';

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  constructor( private http: HttpClient) { }

  getAllPosts(){
    return this.http.get('/posts').map((posts) => {
      return posts;
    });
  }
}

How can I overcome this error? My rxjs version is above 6 and angular version is 10.

like image 791
Kamalka Fernando Avatar asked Jun 09 '26 04:06

Kamalka Fernando


1 Answers

You have to pipe your operators. From the docs

Note that, for Angular apps, we prefer combining operators with pipes, rather than chaining. Chaining is used in many RxJS examples.

Try:

return this.http.get('/posts').pipe(
    map((posts) => {return posts; }),
);
like image 182
Kaustubh Badrike Avatar answered Jun 10 '26 18:06

Kaustubh Badrike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!