TypeError:映射不是函数

时间:2018-10-24 16:41:49

标签: javascript angular typescript http angular6

我正在尝试对API进行POST调用,并且标题中收到错误。我已经检查了所有其他相关问题,并确保没有这些问题。我已经导入了rxjs map运算符。实际上,我在前端Angular 6应用程序中的数百个其他http调用中使用了完全相同的语法,没有问题。

以下是引起问题的代码段:

public createMap(map) {
    map.companyId = this.company.getCompanyId();
    const temp = this.json.clone(map);
    temp.settings = this.json.manageJSON(temp.settings, true);

    return this.authHttp.post(environment.coreApiPath + 'importMaps', temp)
        .pipe(map((res: any) => {
            map.ID = res.ID;
            map.tempName = null;
            this.maps.push(map);
            return map;
        }),
        catchError(error => { throw Error('Custom Error: There was an error when attempting to create this import map.') }));
}

错误出现在读取.pipe(map((res: any) => {

的行上

您知道什么可能导致此问题吗?

这是我的进口商品,以防万一您想知道的事情:

import { HttpClient } from '@angular/common/http';
import { map, catchError } from 'rxjs/operators';

1 个答案:

答案 0 :(得分:6)

您的参数map遮盖了您导入的map

import { map, catchError } from 'rxjs/operators';
//       ^^^------------------- import

// ...

public createMap(map) {
//               ^^^----------- parameter

因此,在createMap中,您不能使用导入的map;无法访问。

考虑重命名参数或重命名导入。

相关问题