自从创建了一个新的 angular 6 项目以来,我复制的一些以前的代码似乎不起作用。这主要似乎是 rxjs 语法
在.map上,它显示错误:
[ts] Property 'map' does not exist on type 'Observable'<User>'.
我似乎在另一个带有.take的文件上遇到了类似的错误
有人能指出我正确的方向来解决这个问题吗?
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, CanActivate, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AngularFireAuth } from 'angularfire2/auth';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/do';
@Injectable()
export class LoginGuardService implements CanActivate {
constructor(
private router: Router,
private auth: AngularFireAuth
) { }
canActivate(): Observable<boolean> {
return this.auth.authState.map(authState => {
if (authState) this.router.navigate(['/folders']);
return !authState;
}).take(1);
}
}
第二后卫
canActivate(路由:ActivatedRouteSnapshot,状态:RouterStateSnapshot):
Observable<boolean> {
this.authGuardStateURL = state.url;
return this.auth.authState.pipe(
take(1)
.map(authState => !!authState)
.do(auth => !auth ? this.router.navigate(['/login']) : true)
)
}