【问题标题】:Unable to find 'map' in Angular 6 service无法在 Angular 6 服务中找到“地图”
【发布时间】:2019-01-09 07:30:43
【问题描述】:

我创建了一个角度服务并尝试进行 Web API 调用。但是在“getItems”函数中的“map”属性中出现错误。 Angular 找不到这个属性。

我也尝试过导入地图功能,但没有任何效果。

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);
    });
  }
}

【问题讨论】:

  • import { map } from 'rxjs/operators';

标签: angular asp.net-web-api2


【解决方案1】:

像这样从“rxjs 5.5+”导入“map”:

import { map } from 'rxjs/operators';

【讨论】:

    猜你喜欢
    • 2019-04-19
    • 2019-07-09
    • 1970-01-01
    • 2019-08-10
    • 2017-03-24
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多