subscribe
map
ped至
status.saved
当然,这个
canActivate
boolean
或者一个
Observable<boolean>
激活
.
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate } from '@angular/router';
import { AuthenticationService } from './auth.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class LocationGuardService implements CanActivate {
constructor(private authService: AuthenticationService) { }
canActivate(route: ActivatedRouteSnapshot): boolean | Observable<boolean> {
if (this.authService.isLoggedIn()) {
if (this.authService.currentUser().user.locationSaved) {
return true;
} else {
return this.authService.isLocationSaved()
.pipe(map(status => status.saved));
}
} else {
return false;
}
}
}