问题描述
对不起,如果这是一个明显的问题。 我正在关注本教程: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()
)
}