14

I tried to use map operator of rxjs in my Angular project but error below occurs

ERROR in src/app/core/service/session.service.ts(88,9): error TS2552: Cannot find name 'map'. Did you mean 'Map'?

Am I missing anything?

Angular CLI 7.0.4

Node 10.13.0

rxjs 6.3.3

typescript 3.1.6

import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';// This is where I import map operator
import { SessionService } from '../service/session.service';

@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate {

  constructor(private session: SessionService,
    private router: Router) {
  }

  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> |boolean {
    return this.session
  .checkLoginState()//Returns an Observable of Session
  .pipe(
    map(session => {
      if (!session.login) {
        this.router.navigate(['']);
      }
      return session.login;
    })
   )
 }
}
3
  • Share your session service code? Commented Nov 27, 2018 at 4:10
  • Possible duplicate of RsJX 'Map' operator is not working in Angular 6 Commented Nov 27, 2018 at 4:22
  • For some reason, I thought this code was session service code. I imported map operator in the correct one, everything went all right. Thank you for the support. Commented Nov 27, 2018 at 4:45

1 Answer 1

35

My error happened, because I forget to check the imports of that functions, VS code always do it but sometimes not. Check if it's the same case, just add...

import { map, catchError } from 'rxjs/operators';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.