Angular, HttpClient; Property '.shareReplay' does not exist on type 'Observable'
Asked Answered
E

1

6

Sorry if this is an obvious question. I am following this tutorial: https://blog.angular-university.io/angular-jwt-authentication/

And i created the Service like in the tutorial but it tells me that Property '.shareReplay' does not exist on type 'Observable', I supose my imports are not correct, but I cant seem to find the correct ones.

import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {User} from "./model/user";

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

  constructor(private http: HttpClient) {
  }

  login(username: string, password: string){
    return this.http.post<User>('/login', {username, password})
      .shareReplay();
  }
}
Easley answered 26/12, 2020 at 15:46 Comment(0)
L
25

This used to be valid before rxjs v5, but now you need to use pipable operators like below

import {shareReplay } from 'rxjs/operators'



login(username: string, password: string){
    return this.http.post<Body>('/login', {username, password}).pipe(
      shareReplay()
    )
      
  }
Laurentian answered 26/12, 2020 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.