Я использую Angular 6 с rxjs ^ 6.0.0 и rxjs-compat ^ 6.5.2, но получаю следующую ошибку, которую не могу устранить:
rxjs__WEBPACK_IMPORTED_MODULE_1 __. Observable.throwне является функцией
Я пробовал следующие решения безуспешно:
Это код, который я использую:
import { Injectable, Inject } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { BehaviorSubject, throwError } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import { map, tap, mergeMap } from 'rxjs/Operators';
import { Login } from "./login/login";
import { CurrentUser } from "./login/current-user";
import { Registration } from "./registrations/registration";
@Injectable()
export class AuthenticationService {
private currentUserSubject: BehaviorSubject<CurrentUser>;
public currentUser: Observable<CurrentUser>;
constructor(private httpClient: HttpClient,
@Inject("BASE_API_URL") private baseUrl: string) {
this.currentUserSubject = new BehaviorSubject<CurrentUser>(JSON.parse(localStorage.getItem('currentUser')));
this.currentUser = this.currentUserSubject.asObservable();
}
public get currentUserValue(): CurrentUser {
return this.currentUserSubject.value;
}
signIn<T>(login: Login) {
return this.httpClient.post<T>(`${this.baseUrl}api/authentication/login`, login)
.pipe(mergeMap(loginResult => {
return this.httpClient.get<Registration>(`${this.baseUrl}api/users/${loginResult.user.id}/registration`)
.pipe(map(registration => {
if (registration.registrationStatusId == 1)
return throwError('Registration is pending approval.');
else if (registration.registrationStatusId == 3)
return throwError('Registration has been rejected.');
let currentUser = new CurrentUser();
currentUser.identity = registration;
currentUser.identity.user = loginResult.user;
currentUser.token = loginResult.token;
currentUser.refreshToken = loginResult.refreshToken;
localStorage.setItem('currentUser', JSON.stringify(currentUser));
this.currentUserSubject.next(currentUser);
}));
}));
}
}