我正在尝试对api进行post调用,并收到标题中的错误。我已经检查了所有其他相关的问题,并确保不是这些问题。我已经导入了rxjsmap运算符。事实上,在我的前端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';

最佳答案

您的参数map正在遮蔽您的导入map

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

// ...

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

因此在createMap中,您不能使用导入的map;它是不可访问的。
考虑重命名该参数,或者重命名导入。

关于javascript - TypeError:映射不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52974132/

10-14 15:03
查看更多