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.
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; }),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With