我写了这个函数,
import { Alert } from './../classes/alert';
import { AlertService } from './alert.service';
import { AlertType } from './../enums/alert-type.enum';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { User } from '../classes/user';
import { Observable } from 'rxjs';
import { of } from 'rxjs';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore, AngularFirestoreDocument } from
'@angular/fire/firestore';
import { switchMap } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AuthService {
public currentUser: Observable<User | null>;
constructor(
private router: Router,
private alertService: AlertService,
private afAuth: AngularFireAuth,
private bd: AngularFirestore,
) {
this.currentUser = this.afAuth.authState
.switchMap((user) => {
if(user){
return this.bd.doc<User>(`users/${user.uid}`).valueChanges();
} else {
return of(null);
}
});
}
但是控制台向我显示了这个错误,
this.afAuth.authState.switchMap 不是函数。
我怎么解决这个问题?