Map is not function in Angular RxJs

Viewed 92

I'm just trying to use the map function but it throws an error.Inside the results.map(results => etc) it says that 'Symbol Map cannot be properly resolved, probably it is located in inaccessible module'

,enter image description here

import { Component, OnInit } from '@angular/core';
import { take, map,filter, tap } from 'rxjs/operators';
etc

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
  public project: IProject;

  constructor(

    private appSer: AppService) { }

  public ngOnInit(): void {

    this.appSer.project$
      .pipe(
        take(1),
        map(results =>
          results.map(result => ({
            ...result,
            square: result.square * 5000

          })))
      )
      .subscribe(
        (result: IProject) => {
          console.log(result);

        },
        (error: any) => {
          console.error(error);
        },

    );
  }
}
2 Answers

Since, the type of results is an object remove the extra map operator.

  .pipe(
    map(result => ({
      ...result,
      square: result.square * 5000
    }))
  )

If result was an array then you would need the extra map operator.

You don't need the second map, just do like so:

      .pipe(
        take(1),
        map(results => ({
            ...result,
            square: result.square * 5000
        }))
      )

(just make sure to match the brackets)

Related