Bhupendra Shukla
Bhupendra Shukla

Reputation: 3914

Unable to find 'map' in Angular 6 service

I have created an angular service and trying to make a web API call. But getting an error in 'map' attribute inside "getItems" function. Angular is unable to find this attribute.

I have also tried to import the map function but nothing works.

import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions, RequestMethod } from '@angular/http';
//import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

import {Employee} from'./employee.model'

@Injectable()
export class EmployeeService {
  selectedEmployee : Employee;
  employeeList : Employee[];
  constructor(private http : Http) { }

  getItems() {
    this.http.get('http://localhost:28750/api/Employee').pipe(map(data => {})).subscribe(result => {
      console.log(result);
    });
  }
}

Upvotes: 0

Views: 105

Answers (1)

Ashish Ranjan
Ashish Ranjan

Reputation: 12960

From "rxjs 5.5+" import "map" like this:

import { map } from 'rxjs/operators';

Upvotes: 3

Related Questions