Working with AngularFireObject and switchMap

后端 未结 3 1783
后悔当初
后悔当初 2021-02-09 06:32

I really don\'t know how to fix this. How can I fix this error?

in user.service.ts:
import { Injectable } from \'@angular/core\';

import { AngularFireDatabase,          


        
3条回答
  •  忘掉有多难
    2021-02-09 06:42

    For RxJS 6 and later, you will need to import and use Observable, map, switchMap differently:

    admin-auth-guard.service.ts:
    import { Injectable } from '@angular/core';
    import { map, switchMap } from 'rxjs/operators'
    import { Observable } from 'rxjs';
    import { UserService } from './user.service';
    import { CanActivate } from '@angular/router';
    import { AuthService } from './auth.service';
    
    @Injectable({
      providedIn: 'root'
    })
    export class AdminAuthGuardService implements CanActivate {
    
      constructor(private auth: AuthService, private userService: UserService) { }
    
      canActivate(): Observable {
        return this.auth.user$.pipe(
          switchMap(user => this.userService.get(user.uid).valueChanges()),
          map (appUser => appUser.isAdmin)
        )
      }
    }
    

提交回复
热议问题