角,HttpClient; 'Observable' 类型不存在属性 '.shareReplay'

问题描述

对不起,如果这是一个明显的问题。 我正在关注本教程:https://blog.angular-university.io/angular-jwt-authentication/

我像在教程中一样创建了服务,但它告诉我属性“.shareReplay”不存在于类型“Observable”上,我假设我的导入不正确,但我似乎无法找到正确的。

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();
  }
}

解决方法

这在 rxjs v5 之前是有效的,但现在您需要使用如下所示的可管道操作符

import {shareReplay } from 'rxjs/operators'



login(username: string,password: string){
    return this.http.post<Body>('/login',{username,password}).pipe(
      shareReplay()
    )
      
  }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...